I'm an Designer and Developers at Geoloqi Esri.
Design, UX, HTML, CSS, JS, lots of it everyday...
SASS or Stylus
SASS if you are using Ruby. Stylus if you using Node. LESS if you afraid of the command line.
80% of SASS, LESS and Stylus is the same.
The 20% that is different is in advanced usage.
$ 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
Variables
Color Transformation
Mixins
Nesting
Loops & Conditionals
Importing
$button-background: #27adec;
.btn {
background: $button-background;
}
@button-background: #27adec;
.btn {
background: @button-background;
}
button-background = #27adec
.btn
background button-background
lighten(@color, 10%);
mix($dark-blue, $light-blue, 25%);
body
color: #444 + #111;
.bordered {
border: 1px solid #000;
border-top-color: #444;
border-bottom-color: #444;
}
#main {
.bordered;
}
Without Params
.border-radius (@r) {
-webkit-border-radius: @r;
-moz-border-radius: @r;
border-radius: @r;
}
#main {
.border-radius(4px);
}
With Params
@mixin border-radius ($radius: 5px) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
border-radius: $radius;
}
#main {
@include border-radius(4px);
}
border-radius(n)
-webkit-border-radius n
-moz-border-radius n
border-radius n
#main
border-radius(5px)
You can nest selectors in all three frameworks.
#main{
margin: 0 auto;
.title {
font-size: 4em;
}
a {
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
}
@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
}
@extend
@media
@content
.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;
}
// 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;
}
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%;
}
}
My favorite SASS feature. Lets you pass whole style blocks into mixins. Similar to Rubys "yeild". Use it for...
<!--[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
Mixins
Namespaces
Scoped Variables
Client Side Processing
In LESS every class is a mixin
.clearfix() {
zoom: 1;
&:before { content: ''; display: block; }
&:after { content: ''; display: table; clear: both; }
}
#content {
.clearfix();
}
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;
}
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; }
You can evalute a javascript expression as a variable
@height: `document.body.clientHeight`;
@width: `document.body.clientWidth`;
Syntax
Language Features
@keyframes
Javascript API
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)
The biggest problem I have with Stylus is with its syntax
Stylus feels very much like a simple programming language
CSS3 keyframes are awesome, Stylus makes then easy
@keyframes pulse
0%, 100%
-webkit-transform translateX(0);
20%, 60%
-webkit-transform translateX(-10px);
40%, 80%
-webkit-transform translateX(10px);
This is awesome!
You could do a whole talk on the Stylus API, here are some ideas...
#feedback
fixed: bottom right
#logo
image: '/img/logo.png'
h1
overflow: ellipsis
LESS just doesn't have the features or power of SASS or Stylus
Both have similar features, a powerful plugin ecosystem, and lots of CSS3 helpers.