SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Downloaden Sie, um offline zu lesen
CSS Preprocessors
Sass, Less and Stylus
Patrick Arlt - @patrickarlt
Some Background
I'm an Designer and Developers at Geoloqi Esri.
Design, UX, HTML, CSS, JS, lots of it everyday...
Ok Ok, which is best?
Really Short Answer
SASS or Stylus
Slightly Longer Answer
SASS if you are using Ruby. Stylus if you using Node. LESS if
you afraid of the command line.
80/20
80% of SASS, LESS and Stylus is the same.
The 20% that is different is in advanced usage.
Installing
SASS
LESS
Stylus
$ gem install sass
$ sass --watch style.scss:style.css
<link rel="stylesheet/less" type="text/css" href="styles.less">
<script src="less.js" type="text/javascript"></script>
$ npm install less
$ lessc styles.less
$ npm install stylus
$ stylus css --watch
The 80%
Variables
Color Transformation
Mixins
Nesting
Loops & Conditionals
Importing
Variables
SASS
LESS
Stylus
$button-background: #27adec;
.btn {
background: $button-background;
}
@button-background: #27adec;
.btn {
background: @button-background;
}
button-background = #27adec
.btn
background button-background
Color Transformations
SASS
LESS
Stylus
lighten(@color, 10%);
mix($dark-blue, $light-blue, 25%);
body
color: #444 + #111;
Without Params With Params
LESS Mixins
.bordered {
border: 1px solid #000;
border-top-color: #444;
border-bottom-color: #444;
}
#main {
.bordered;
}
.border-radius (@r) {
-webkit-border-radius: @r;
-moz-border-radius: @r;
border-radius: @r;
}
#main {
.border-radius(4px);
}
SASS Mixins
@mixin border-radius ($radius: 5px) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
border-radius: $radius;
}
#main {
@include border-radius(4px);
}
Stylus Mixins
border-radius(n)
-webkit-border-radius n
-moz-border-radius n
border-radius n
#main
border-radius(5px)
Nesting
You can nest selectors in all three frameworks.
#main{
margin: 0 auto;
.title {
font-size: 4em;
}
a {
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
}
Imports
All 3 support importing from other files or libraries...
@import "compass/css3";
@import "susy";
@import "animation/animate";
@import "myfile.scss";
#main {
@include border-radius(5px); // from compass/css3
@include span-columns(10); // from susy
@include animation(fadeIn); // from animation/animate
background: $background-color; // from myfile.scss
}
#sidebar {
@include span-columns(2 omega); // from susy
}
More Features
Conditionals like "if, "when"
MATH!
SASS and Stylus
Loops like "for", "while", and "each"
Much more depth then LESS
Custom functions without the Ruby/JS API
The 20%
SASS
@extend
@media
@content
@extend
.button {
background: $blue;
color: #fff
}
.my-special-button {
@extend .button;
font-size: 2em;
}
.button, .my-special-button {
background: $blue;
color: #fff
}
.my-special-button {
font-size: 2em;
}
@extend Selectors
// This won't be compiled
#context a%extreme {
color: red;
font-weight: bold;
font-size: 2em;
}
.notice {
@extend %extreme;
}
#content a.notice {
color: $red;
font-weight: bold;
font-size: 2em;
}
@media
Declare media queries inside selectors
#content {
width: 65%;
margin: 0 auto;
@media only screen and (max-width : 767px) {
width: 90%;
}
}
#content {
width: 65%;
margin: 0 auto;
}
@media only screen and (max-device-width : 768px) {
#content {
width: 90%;
}
}
@content
My favorite SASS feature. Lets you pass whole style blocks
into mixins. Similar to Rubys "yeild". Use it for...
Media Query Helpers
Retina Images
IE Specific Styles
CSS3 Polyfills
@content Example
<!--[if IE 7 ]><html class="ie ie7" lang="en"><![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"><![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"><!--<![endif]-->
@mixin for-ie(){
html.ie &{
@content;
}
}
#browser-warning {
display:none;
@include for-ie(){
display:block
}
}
Compass
makes SASS even more awesome
CSS3 mixins, supports almost every CSS3 feature
Typography styling helpers
Generates CSS sprites
Produces cross browser CSS for IE6,7,8
Plugin framework via Rubygems
Compass
Compass Bootstrap
Foundation Framework
Susy - Responsive Grids
Compass Animation
LESS
Mixins
Namespaces
Scoped Variables
Client Side Processing
Mixins
In LESS every class is a mixin
.clearfix() {
zoom: 1;
&:before { content: ''; display: block; }
&:after { content: ''; display: table; clear: both; }
}
#content {
.clearfix();
}
Namespaceing Mixins
Organize your mixins into namespaces
#my-framework {
.button () {
display: block;
border: 1px solid @dark-blue;
background-color: @blue;
color: @light-blue;
}
}
.a-button {
#my-framework > .button;
}
Scoped Variables
Variables have scope which makes them it easy to override
@text-color: #444;
@background-color: #fafafa;
body {
color: @text-color;
background: @background-color;
}
.inverse {
@text-color: #fafafa;
@background-color: #444;
color: @text-color;
background: @background-color;
}
h1 { color: @text-color + #111; }
Client-Side Compiling
Great for static HTML sites
Sites where you don't have a real server (S3)
You can evaluate Javascript in your .less files
Evalute Javascipt
You can evalute a javascript expression as a variable
@height: `document.body.clientHeight`;
@width: `document.body.clientWidth`;
Stylus
Syntax
Language Features
@keyframes
Javascript API
Stylus Syntax
Whitespace Based
Can omit { : ; }
The biggest problem I have with Stylus is with its syntax
border-radius()
-webkit-border-radius arguments
-moz-border-radius arguments
border-radius arguments
body
font 12px Helvetica, Arial, sans-serif
a.button
border-radius(5px)
Stylus Language
Stylus feels very much like a simple programming language
Ruby-like ranges [1..5], [0...5]
for/in loops
real operator precidence
complex conditionals if/else if/else, unless/else, postfix
conditionals
@keyframe Support
CSS3 keyframes are awesome, Stylus makes then easy
This is awesome!
@keyframes pulse
0%, 100%
-webkit-transform translateX(0);
20%, 60%
-webkit-transform translateX(-10px);
40%, 80%
-webkit-transform translateX(10px);
Javascript API
You could do a whole talk on the Stylus API, here are some
ideas...
Declare really custom functions
Use Node modules like canvas
Do Compass-like sprite generation
Create your own CSS framework
Nib
CSS3 helpers - gradiants, border-radius, ect...
Mixins for common css patterns
Extends CSS with new properties and values
#feedback
fixed: bottom right
#logo
image: '/img/logo.png'
h1
overflow: ellipsis
Smackdown!
Who Wins?
LESS Looses
LESS just doesn't have the features or power of SASS or
Stylus
Nothing like Compass or Nib
No plugin system
Can't define your own functions with just LESS
Doesn't output any debugging info
SASS vs. Stylus
Both have similar features, a powerful plugin ecosystem,
and lots of CSS3 helpers.
SASS syntax is close to CSS
Stylus is closer to a programming language
If you use Ruby you will probally use SASS
If you use Node you will probally use Stylus
Questions
Patrick Arlt - @patrickarlt
CSS Preprocessors. Comparing SASS, LESS and Stylus

Weitere ähnliche Inhalte

Andere mochten auch

باللغة العربية jQuery دورة
 باللغة العربية jQuery دورة باللغة العربية jQuery دورة
باللغة العربية jQuery دورةanees abu-hmaid
 
Canvas دورة باللغة العربية
Canvas دورة باللغة العربيةCanvas دورة باللغة العربية
Canvas دورة باللغة العربيةanees abu-hmaid
 
java script course دورة جافا سكربت باللغة العربية
java script course دورة جافا سكربت باللغة العربيةjava script course دورة جافا سكربت باللغة العربية
java script course دورة جافا سكربت باللغة العربيةanees abu-hmaid
 
باللغة العربية SASS دورة
  باللغة العربية SASS دورة   باللغة العربية SASS دورة
باللغة العربية SASS دورة anees abu-hmaid
 
باللغة العربية JSON دورة
  باللغة العربية JSON دورة   باللغة العربية JSON دورة
باللغة العربية JSON دورة anees abu-hmaid
 
Bootstrap3 دورة باللغة العربية
Bootstrap3 دورة باللغة العربيةBootstrap3 دورة باللغة العربية
Bootstrap3 دورة باللغة العربيةanees abu-hmaid
 
Ecmascript 6 (ES6) جافا سكربت (6)
Ecmascript 6 (ES6) جافا سكربت (6)Ecmascript 6 (ES6) جافا سكربت (6)
Ecmascript 6 (ES6) جافا سكربت (6)anees abu-hmaid
 
구문과 의미론(정적 의미론까지)
구문과 의미론(정적 의미론까지)구문과 의미론(정적 의미론까지)
구문과 의미론(정적 의미론까지)Nam Hyeonuk
 
دورة CSS3 باللغة العربية
دورة CSS3 باللغة العربيةدورة CSS3 باللغة العربية
دورة CSS3 باللغة العربيةanees abu-hmaid
 
Intro to css & sass
Intro to css & sassIntro to css & sass
Intro to css & sassSean Wolfe
 
Blue ocean strategy arabic
Blue ocean strategy arabicBlue ocean strategy arabic
Blue ocean strategy arabicMohammad Alyan
 
Sass - Getting Started with Sass!
Sass - Getting Started with Sass!Sass - Getting Started with Sass!
Sass - Getting Started with Sass!Eric Sembrat
 
Sass and compass workshop
Sass and compass workshopSass and compass workshop
Sass and compass workshopShaho Toofani
 
게임 스타트업 시작하기
게임 스타트업 시작하기게임 스타트업 시작하기
게임 스타트업 시작하기기룡 남
 
[D2]thread dump 분석기법과 사례
[D2]thread dump 분석기법과 사례[D2]thread dump 분석기법과 사례
[D2]thread dump 분석기법과 사례NAVER D2
 
[D2]pinpoint 개발기
[D2]pinpoint 개발기[D2]pinpoint 개발기
[D2]pinpoint 개발기NAVER D2
 

Andere mochten auch (19)

jQuery UI (Effect)
jQuery UI (Effect) jQuery UI (Effect)
jQuery UI (Effect)
 
باللغة العربية jQuery دورة
 باللغة العربية jQuery دورة باللغة العربية jQuery دورة
باللغة العربية jQuery دورة
 
Canvas دورة باللغة العربية
Canvas دورة باللغة العربيةCanvas دورة باللغة العربية
Canvas دورة باللغة العربية
 
java script course دورة جافا سكربت باللغة العربية
java script course دورة جافا سكربت باللغة العربيةjava script course دورة جافا سكربت باللغة العربية
java script course دورة جافا سكربت باللغة العربية
 
باللغة العربية SASS دورة
  باللغة العربية SASS دورة   باللغة العربية SASS دورة
باللغة العربية SASS دورة
 
باللغة العربية JSON دورة
  باللغة العربية JSON دورة   باللغة العربية JSON دورة
باللغة العربية JSON دورة
 
Bootstrap3 دورة باللغة العربية
Bootstrap3 دورة باللغة العربيةBootstrap3 دورة باللغة العربية
Bootstrap3 دورة باللغة العربية
 
Ecmascript 6 (ES6) جافا سكربت (6)
Ecmascript 6 (ES6) جافا سكربت (6)Ecmascript 6 (ES6) جافا سكربت (6)
Ecmascript 6 (ES6) جافا سكربت (6)
 
구문과 의미론(정적 의미론까지)
구문과 의미론(정적 의미론까지)구문과 의미론(정적 의미론까지)
구문과 의미론(정적 의미론까지)
 
Sass presentation
Sass presentationSass presentation
Sass presentation
 
دورة CSS3 باللغة العربية
دورة CSS3 باللغة العربيةدورة CSS3 باللغة العربية
دورة CSS3 باللغة العربية
 
Intro to css & sass
Intro to css & sassIntro to css & sass
Intro to css & sass
 
Blue ocean strategy arabic
Blue ocean strategy arabicBlue ocean strategy arabic
Blue ocean strategy arabic
 
Sass - Getting Started with Sass!
Sass - Getting Started with Sass!Sass - Getting Started with Sass!
Sass - Getting Started with Sass!
 
Sass and compass workshop
Sass and compass workshopSass and compass workshop
Sass and compass workshop
 
c#
c#c#
c#
 
게임 스타트업 시작하기
게임 스타트업 시작하기게임 스타트업 시작하기
게임 스타트업 시작하기
 
[D2]thread dump 분석기법과 사례
[D2]thread dump 분석기법과 사례[D2]thread dump 분석기법과 사례
[D2]thread dump 분석기법과 사례
 
[D2]pinpoint 개발기
[D2]pinpoint 개발기[D2]pinpoint 개발기
[D2]pinpoint 개발기
 

Kürzlich hochgeladen

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Kürzlich hochgeladen (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

CSS Preprocessors. Comparing SASS, LESS and Stylus

  • 1. CSS Preprocessors Sass, Less and Stylus Patrick Arlt - @patrickarlt
  • 2. Some Background I'm an Designer and Developers at Geoloqi Esri. Design, UX, HTML, CSS, JS, lots of it everyday...
  • 3. Ok Ok, which is best? Really Short Answer SASS or Stylus Slightly Longer Answer SASS if you are using Ruby. Stylus if you using Node. LESS if you afraid of the command line.
  • 4. 80/20 80% of SASS, LESS and Stylus is the same. The 20% that is different is in advanced usage.
  • 5. Installing SASS LESS Stylus $ gem install sass $ sass --watch style.scss:style.css <link rel="stylesheet/less" type="text/css" href="styles.less"> <script src="less.js" type="text/javascript"></script> $ npm install less $ lessc styles.less $ npm install stylus $ stylus css --watch
  • 7. Variables SASS LESS Stylus $button-background: #27adec; .btn { background: $button-background; } @button-background: #27adec; .btn { background: @button-background; } button-background = #27adec .btn background button-background
  • 9. Without Params With Params LESS Mixins .bordered { border: 1px solid #000; border-top-color: #444; border-bottom-color: #444; } #main { .bordered; } .border-radius (@r) { -webkit-border-radius: @r; -moz-border-radius: @r; border-radius: @r; } #main { .border-radius(4px); }
  • 10. SASS Mixins @mixin border-radius ($radius: 5px) { -webkit-border-radius: $radius; -moz-border-radius: $radius; border-radius: $radius; } #main { @include border-radius(4px); }
  • 12. Nesting You can nest selectors in all three frameworks. #main{ margin: 0 auto; .title { font-size: 4em; } a { text-decoration: none; &:hover { text-decoration: underline; } } }
  • 13. Imports All 3 support importing from other files or libraries... @import "compass/css3"; @import "susy"; @import "animation/animate"; @import "myfile.scss"; #main { @include border-radius(5px); // from compass/css3 @include span-columns(10); // from susy @include animation(fadeIn); // from animation/animate background: $background-color; // from myfile.scss } #sidebar { @include span-columns(2 omega); // from susy }
  • 14. More Features Conditionals like "if, "when" MATH! SASS and Stylus Loops like "for", "while", and "each" Much more depth then LESS Custom functions without the Ruby/JS API
  • 17. @extend .button { background: $blue; color: #fff } .my-special-button { @extend .button; font-size: 2em; } .button, .my-special-button { background: $blue; color: #fff } .my-special-button { font-size: 2em; }
  • 18. @extend Selectors // This won't be compiled #context a%extreme { color: red; font-weight: bold; font-size: 2em; } .notice { @extend %extreme; } #content a.notice { color: $red; font-weight: bold; font-size: 2em; }
  • 19. @media Declare media queries inside selectors #content { width: 65%; margin: 0 auto; @media only screen and (max-width : 767px) { width: 90%; } } #content { width: 65%; margin: 0 auto; } @media only screen and (max-device-width : 768px) { #content { width: 90%; } }
  • 20. @content My favorite SASS feature. Lets you pass whole style blocks into mixins. Similar to Rubys "yeild". Use it for... Media Query Helpers Retina Images IE Specific Styles CSS3 Polyfills
  • 21. @content Example <!--[if IE 7 ]><html class="ie ie7" lang="en"><![endif]--> <!--[if IE 8 ]><html class="ie ie8" lang="en"><![endif]--> <!--[if (gte IE 9)|!(IE)]><!--><html lang="en"><!--<![endif]--> @mixin for-ie(){ html.ie &{ @content; } } #browser-warning { display:none; @include for-ie(){ display:block } }
  • 22. Compass makes SASS even more awesome CSS3 mixins, supports almost every CSS3 feature Typography styling helpers Generates CSS sprites Produces cross browser CSS for IE6,7,8 Plugin framework via Rubygems Compass Compass Bootstrap Foundation Framework Susy - Responsive Grids Compass Animation
  • 24. Mixins In LESS every class is a mixin .clearfix() { zoom: 1; &:before { content: ''; display: block; } &:after { content: ''; display: table; clear: both; } } #content { .clearfix(); }
  • 25. Namespaceing Mixins Organize your mixins into namespaces #my-framework { .button () { display: block; border: 1px solid @dark-blue; background-color: @blue; color: @light-blue; } } .a-button { #my-framework > .button; }
  • 26. Scoped Variables Variables have scope which makes them it easy to override @text-color: #444; @background-color: #fafafa; body { color: @text-color; background: @background-color; } .inverse { @text-color: #fafafa; @background-color: #444; color: @text-color; background: @background-color; } h1 { color: @text-color + #111; }
  • 27. Client-Side Compiling Great for static HTML sites Sites where you don't have a real server (S3) You can evaluate Javascript in your .less files Evalute Javascipt You can evalute a javascript expression as a variable @height: `document.body.clientHeight`; @width: `document.body.clientWidth`;
  • 29. Stylus Syntax Whitespace Based Can omit { : ; } The biggest problem I have with Stylus is with its syntax border-radius() -webkit-border-radius arguments -moz-border-radius arguments border-radius arguments body font 12px Helvetica, Arial, sans-serif a.button border-radius(5px)
  • 30. Stylus Language Stylus feels very much like a simple programming language Ruby-like ranges [1..5], [0...5] for/in loops real operator precidence complex conditionals if/else if/else, unless/else, postfix conditionals
  • 31. @keyframe Support CSS3 keyframes are awesome, Stylus makes then easy This is awesome! @keyframes pulse 0%, 100% -webkit-transform translateX(0); 20%, 60% -webkit-transform translateX(-10px); 40%, 80% -webkit-transform translateX(10px);
  • 32. Javascript API You could do a whole talk on the Stylus API, here are some ideas... Declare really custom functions Use Node modules like canvas Do Compass-like sprite generation Create your own CSS framework
  • 33. Nib CSS3 helpers - gradiants, border-radius, ect... Mixins for common css patterns Extends CSS with new properties and values #feedback fixed: bottom right #logo image: '/img/logo.png' h1 overflow: ellipsis
  • 35. LESS Looses LESS just doesn't have the features or power of SASS or Stylus Nothing like Compass or Nib No plugin system Can't define your own functions with just LESS Doesn't output any debugging info
  • 36. SASS vs. Stylus Both have similar features, a powerful plugin ecosystem, and lots of CSS3 helpers. SASS syntax is close to CSS Stylus is closer to a programming language If you use Ruby you will probally use SASS If you use Node you will probally use Stylus
  • 37. Questions Patrick Arlt - @patrickarlt