SASS Flashcards
Create a loop where variable i goes from 1 to 10.
@for $i from 1 through 10 {
.box-#{$i} { // some styles }
Interpolate the variable $i so you can make classes called .box-1, .box-2, etc, based on a loop.
.box-#{$i} { // some styles }
Assuming you have variable $i = 1, calculate percentage of 1/12 in order to say width: 8.33333%;
width: percentage($i / 12); // no need for % sign
What’s a sass map?
A set of key/value pairs, like a js object. Syntax is:
$sizes: ( small: 10%, medium: 25%, large: 100% )
// use parens and commas.
Loop over a sass map
@each $key, $value in $map { … }
Create a reusable media query mixin
@mixin smallScreen ($w: 800px) {
@media screen and (max-width: $w) {
@content
}
Instead of writing @media for a media query, use a mixin called ‘smallScreen’ to style an h1 element.
@include smallScreen {
h1 { // styles
Create a function taking a number and returning it as an em.
@function toEm($num) {
@return #{$num}em; // or $num * 1em;
Use a sass function called getWidth() in a style value for width.
width: getWidth(n);