Inheritance and Polymorphism in SASS
Inheritance and Polymorphism in SASS
Nesting .button {
···
.markdown-body { }
a{ .push-button {
color: blue; @extend .button;
&:hover { }
color: red;
} Composing
}
@import './other_sass_file';
}
@use './other_sass_file';
to properties
The @import rule is discouraged because will get
text: {
eventually removed from the language.
align: center; // like text-align: center
Instead, we should use the @use rule.
transform: uppercase; // like text-transform:
The .scss or .sass extension is optional.
uppercase
#Color functions
}
Comments rgba
/* Block comments */ rgb(100, 120, 140)
// Line comments rgba(100, 120, 140, .5)
Mixins rgba($color, .5)
Mixing
@mixin heading-font {
font-family: sans-serif; mix($a, $b, 10%) // 10% a, 90% b
font-weight: bold;
Modifying HSLA
darken($color, 5%) str-slice(hello, 2, 5) // "ello" - it's 1-based, not 0-
lighten($color, 5%) based
saturate($color, 5%) str-insert("abcd", "X", 1) // "Xabcd"
desaturate($color, 5%) Units
grayscale($color)
adjust-hue($color, 15deg) unit(3em) // 'em'
complement($color) // like adjust-hue(_, 180deg) unitless(100px) // false
invert($color)
fade-in($color, .5) // aka opacify() Numbers
fade-out($color, .5) // aka transparentize() - halves
the opacity floor(3.5)
rgba($color, .5) // sets alpha to .5 ceil(3.5)
round(3.5)
Getting individual values abs(3.5)
min(1, 2, 3)
HSLA max(1, 2, 3)
hue($color) // → 0deg..360deg percentage(.5) // 50%
saturation($color) // → 0%..100% random(3) // 0..3
lightness($color) // → 0%..100%
alpha($color) // → 0..1 (aka opacity()) Misc
RGB
red($color) // → 0..255 variable-exists(red) // checks for $red
green($color) mixin-exists(red-text) // checks for @mixin red-text
blue($color) function-exists(redify)
See: hue(), red() global-variable-exists(red)
selector-append('.menu', 'li', 'a') // .menu li a
Adjustments selector-nest('.menu', '&:hover li') // .menu:hover li
selector-extend(...)
// Changes by fixed amounts selector-parse(...)
adjust-color($color, $blue: 5) selector-replace(...)
adjust-color($color, $lightness: -30%) // like selector-unify(...)
darken(_, 30%)
adjust-color($color, $alpha: -0.4) // like fade-
out(_, .4)
adjust-color($color, $hue: 30deg) // like adjust-
hue(_, 15deg)
// Changes via percentage
scale-color($color, $lightness: 50%)
// Changes one property completely
change-color($color, $hue: 180deg)
change-color($color, $blue: 250) Feature check
Supported: $red $green $blue $hue $saturation $ligh
feature-exists(global-variable-shadowing)
tness $alpha
#Other functions Features
global-variable-shadowing
extend-selector-pseudoclass
units-level-3
at-error
Strings
For loops
unquote('hello')
quote(hello) @for $i from 1 through 4 {
to-upper-case(hello) .item-#{$i} { left: 20px * $i; }
to-lower-case(hello) }
str-length(hello world) Each loops (simple)
$menu-items: home about services contact; length($list)
$i: 6;
@while $i > 0 {
.item-#{$i} { width: 2em * $i; }
$i: $i - 2;
}
Conditionals
@media #{$tablet}
font: #{$size}/#{$line-height}
url("#{$background}.jpg")
Lists
$list: (a b c);