Sass Flashcards
Sass stands for…
Syntactically Awesome StyleSheets
Sass to CSS is
a language extension
what Sass does in a nutshell
adds features that aren’t available using basic CSS syntax
Sass makes it easier for…
developers to simplify and maintain the style sheets for projects
Sass is a…
preprocessor, it takes code written in Sass syntax and converts to basic CSS
With Sass you can…
create variables, nest CSS rules into others, import other Sass files
creates more compact, easier to read code
how many syntaxes available for Sass?
2:
- SCSS (sassy CSS)
- indented syntax or just Sass
SCSS
extension of CSS synatx. every valid CSS stylesheet is a valid SCSS file with the same meaning.
have .scss extension
Indented Sass
older syntax, uses indentation rather than brackets to indicate nesting of selectors,
newlines rather than semicolons to separate properties
have .sass extension
in Sass, variables start with
$ followed by the variable name
set style tag to use sass
nesting in Sass
parent {
child {};
}
a mixin in Sass is
a group of CSS declarations that can be reused throughout the stylesheet
use case for mixin
the treatment of box-shadow by different browsers has to be handled by prefixes like -webkit or -moz
implement mixin (box shadow example)
starts with @mixin then name (parameters optional)
{all the basic CSS code that you would have used}
@mixin box-shadow($x, $y, $blur, $c){ -webkit-box-shadow: $x $y $blur $c; -moz-box-shadow: $x $y $blur $c; -ms-box-shadow: $x $y $blur $c; box-shadow: $x $y $blur $c; }
a mixin is called with
@include directive
div {
@include box-shadow(0px, 0px, 4px, #fff);
}
add logic to style
@if, @else if, @else
@mixin text-effect($val) { @if $val == danger { color: red; } @else if $val == alert { color: yellow; } @else if $val == success { color: green; } @else { color: black; } }
create a Sass loop
@for
@for is used 2 ways
start through end
start to end
the main difference between start to end and start through end in @for loop is
start to end excludes the end number
start through end includes the end number
syntax for @for loop (start through end)
@for $i from 1 through 12 {
.col-#{$i} { width: 100%/12 * $i; }
}
this is a powerful way to create a grid layout
@each
loops over each item in a list or map.
On each iteration, the variable gets assigned to the current value from the list or map.
@each example (assign color to blue, red, green) – using list
@each $color in blue, red, green {
.#{$color}-text {color: $color;}
}
@each example (assign color to blue, red, green) – using map
$colors: (color1: blue, color2: red, color3: green);
@each $key, $color in $colors {
.#{$color}-text {color: $color;}
}