that adds power and elegance to the basic language.“ Sass improves CSS’s syntax in order to provide extra features and handy tools. The point is not to turn CSS into a fully-featured programming language; Sass wants to help where CSS fails.
a program that processes its input data to produce output that is used as input to another program. There are also many other CSS preprocessors like LESS or Stylus.
the gap between Sass and CSS by providing a CSS-friendly syntax called SCSS(Sassy CSS). The motto is: if it’s valid CSS, it’s valid SCSS. Since then, Sass (the preprocessor) has been providing two different syntaxes: Sass and SCSS. They are strictly equivalent in features.
way for stylesheet authors to compute long selectors by nesting shorter selectors. // Sass nav ul color: red li color: black a text-decoration: none &:hover color: white // CSS nav ul { color: red; } nav li { color: black; } nav a { text-decoration: none; } nav a:hover{ color: white; }
also doesn’t require strings to be quoted, but it is a good practice. This improves the understanding. //Yes $font-stack: 'Helvetica Neue Light', 'Helvetica', sans-serif //No $font-stack: Helvetica Neue Light, Helvetica, sans-serif
project in different partials ( name starts with _ ) included by @import directive. Remote resources can be imported with the same directive too. No more 2.000 CSS lines.
. The directive @each set $var in each element of the list or map. $colors: (sexy: #FA6ACC, glamour: #F02A52, sky: #09A6E4) $list: ‘sexy’, ‘glamour’, ‘sky’ @each $item in $list .item-#{$item} background-color: map-get($colors, $item)
allow us to reuse values without having to copy them over and over again. Variables must be defined before the use. Scoping: local variables override previous and global variables. Pay attention! Sass doesn’t have constants. The convention say to write variables that you don’t want to override UPCASED.
a unitless number to a percentage. round(12.4) // 12 => Rounds a number to the nearest whole number. random([$limit]) // Returns a random number. Default is between 0 and 1.
a list, returns 1) nth($list, $index) // returns the value at $index position in $list append($list, $value[, $separator]) // appends $value to the end of $list using $separator join($list1, $list2[, $separator]) // appends $list2 to $list1 zip(*$lists) // WTF?
Only the selectors that extend them will be included in the output stylesheet. //Sass %red-button background-color: blue color: white .button @extend %red-button margin: 0 .huge-button @extend %red-button .another-button @extend %red-button //CSS .button { background-color: blue; color: white; margin: 0; } .huge-button { background-color: blue; color: white; } .another-button { background-color: blue; color: white; }
Only the selectors that extend them will be included in the output stylesheet. //Sass %red-button background-color: blue color: white .button @extend %red-button margin: 0 .huge-button @extend %red-button .another-button @extend %red-button //CSS .button, .huge- button, .another-button { background-color: blue; color: white; } .button { margin: 0; }
groups: Block: The root of the component. Element: A component part of the Block. Modifier: A variant or extension of the Block. .room {} .room__head {} .room--bathroom {}
there. Developed by Chris Eppstein, one of the two core designers of Sass. Compass is composed by: . Vendor prefixes . Math helpers like cos, sin, pi and such . Color helpers like shade, tint and such . Image helpers like image-width and image-height . A sprite builder We don’t use Compass anymore.