Slides of my 18-minutes talk "Keep Calm and Write Sass" at dotCSS 2014 (November 14th).
View Slide
“Your CSSis a mess.”Jonathan Snook
Your CSSis a mess.
Broken fromthe start?
Sass tothe rescue!
But... wait.
It's not allbright andshiny.
Complexity,maintainability,scary code...
Don'tover-{think|engineer}
KISSKeep ItSimple, Stupid!
KYSSKeep YourSass SimpleKeep Sass Simple at SitePoint
KYSSSKeep YourSass Simple &Straightforward
KYSSSSKeep YourSass Simple, Smart &Straightforward...
Writesimple APIs
.parent {@include _(10 8 6 4,$gutter: alpha omega omega default);}
.parent {width: 100%;@include respond-to("desktop") {width: 75%;}}
$color: map-get(map-get(map-get($themes, "shopping"), "colors"), "secondary");
$color: theme-conf("shopping", "colors", "secondary");
Beware ofselector nestingBeware of selector nesting at SitePoint
Don't doeverything inSass
RethinkingAtwood's law
Anything that canbe written in Sasswill eventually bewritten in Sass(probably by me)
SassyJSON@include json-encode(("cats" : true,"answer" : 42));// {"cats": true, "answer": 42}github.com/HugoGiraudel/SassyJSON
SassySort$list: sort("How" "cool" "Sass" "is?" 42);// 42 "cool" "How" "is?" "Sass"github.com/HugoGiraudel/SassySort
SassyBitwise$value: bitwise(42 '&' 48);// 32github.com/HugoGiraudel/SassyBitwise
Some thingsshouldn'tbe done
Vendorprefixing?Maybe not.
AutoprefixerLess codeUp-to-dategithub.com/postcss/autoprefixer
REM?Think twice.
px_to_remLess codeEasiergithub.com/songawee/px_to_rem
Cleanyour code
.selector {color: blue;backgroud: url(unicorn.png);-webkit-transform: rotate(15deg);transform: rotate(15deg);position: relative }
.selector {position: relative;-webkit-transform: rotate(15deg);transform: rotate(15deg);color: blue;backgroud: url("unicorn.png");}
cssguidelin.es
scss-lintgithub.com/causes/scss-lint
Documentyour code
.selector {overflow: hidden;white-space: nowrap;margin: -.5em;z-index: 42;}
/*** 1. Clear inner floats* 2. Force all items on same line* 3. Cancel items padding* 4. Above content, below modal*/.selector {overflow: hidden; /* 1 */white-space: nowrap; /* 2 */margin: -.5em; /* 3 */z-index: 42; /* 4 */}
Documentyour Sass
SassDocsassdoc.com
/// Mixin to size an element/// @access public/// @param {Number} $width - Width/// @param {Number} $height - Height/// @example scss - Sizing an element/// .element {/// @include size(100%, 5em);/// }SassDoc
SassDoc
Testyour code
TrueorBootCamp
@include describe("A suite") {@include it("contains spec with expectation") {@include should(expect(2 + 2),to(be(4)));}}Bootcampgithub.com/thejameskyle/bootcamp
KISS - KYSSclean, test,document
And everythingwill be fine.
Thanks!@HugoGiraudel