Some Background Sass Modules Selector Nesting Imperative Variables Control Structures Mixins & Functions Map References
Original Sass Mixins =grid-container(!grid = !total_cols ) :margin-left auto :margin-right auto :overflow hidden :width=(!grid * !col_width) + ((!grid - 1) * !gutter_width) :max-width 99%
Some Background Sass Modules Selector Nesting Imperative Variables Control Structures Mixins & Functions Map References
sass/ tools/ config/ _colors.scss _fonts.scss _sizes.scss _index.scss initial/ patterns/ layouts/ components/ style.scss
@use 'colors' // default 'colors' namespace// $_private is not availablea { color: colors.$brand; background: colors.tint(maroon, 95%);}
sass/config/_index.scss @forward 'color' as color-*;@forward 'fonts' as font-*;@forward 'scale' as size-*;
Some Background Sass Modules Selector Nesting Imperative Variables Control Structures Mixins & Functions Map References
nav { background: silver;}nav ul { margin: 0; padding: 0; list-style: none;}nav li { display: inline-block; }
nav { background: silver; ul { margin: 0; padding: 0; list-style: none; } li { display: inline-block; }}
.block { // .block {} &__element { // .block__element {} &--modifier { // .block__element--modifier {} } }}
Don’t Overly Sandbox Avoid the temptation to mimic html structure body { nav { ul { li { display: inline-block; } } }}
Some Background Sass Modules Selector Nesting Imperative Variables Control Structures Mixins & Functions Map References
$color-brand-blue: hsl(195, 85%, 35%);$color-brand-orange: hsl(24, 100%, 39%);$color-brand-pink: hsl(330, 85%, 48%);
// 'colors' module...$brand: ( 'blue': hsl(195, 85%, 35%), 'orange': hsl(24, 100%, 39%), 'pink': hsl(330, 85%, 48%),);
Some Background Sass Modules Selector Nesting Imperative Variables Control Structures Mixins & Functions Map References
@use 'sass:color';button { color: $btn-color; @if (color.lightness($btn-color) > 50%) { background: black; } @else { background: white; }}
@for Loops Number Ranges @for $n from 1 through 10 { .item:nth-child(#{$n}) { // generate styles for nth-child 1-10 }}
@each Loops Lists & Maps html { // each <key>, <value> in <map> @each $name, $color in $brand { --color-brand-#{$name}: #{$color}; }}
@use 'sass:color';@use 'sass:map';@each $name, $color in $colors { $generated: ( '#{$name}-light': color.scale($color, $lightness: 50%), '#{$name}-dark': color.scale($color, $lightness: -50%), ); $colors: map.merge($colors, $generated);}
@mixin background($color-name) { background: map.get($color-name);}// You can't interpolate variable names...// $#{$color-name}
Some Background Sass Modules Selector Nesting Imperative Variables Control Structures Mixins & Functions Map References
@mixin button($background, $text) { background: $background; color: $text; border: thin solid; border-radius: 0.12em; font: inherit; padding: 0.25em 1em;}
@use 'sass:color';@function contrast($color) { @if (color.lightness($color) > 50%) { @return black; } @else { @return white; } }
@mixin button($background) { background: $background; color: contrast($background); border: thin solid; border-radius: 0.12em; font: inherit; padding: 0.25em 1em;}
@use 'sass:color';@use 'sass:map';@each $name, $color in $colors { $generated: ( '#{$name}-light': color.scale($color, $lightness: 50%), '#{$name}-dark': color.scale($color, $lightness: -50%), ); $colors: map.merge($colors, $generated);}
@use 'sass:color';@use 'sass:map';@function build-palette($colors) { @each $name, $color in $colors { $generated: ( '#{$name}-light': color.scale($color, $lightness: 50%), '#{$name}-dark': color.scale($color, $lightness: -50%), ); $colors: map.merge($colors, $generated); }}
My job is to make sure the system is modular and flexible enough to be used in any number of unpredictable ways. – Mina Markham, Pantsuit
Some Background Sass Modules Selector Nesting Imperative Variables Control Structures Mixins & Functions Map References
Internal Reference $colors: ( 'brand-blue': hsl(195, 85%, 35%), 'action': 'brand-blue', // just a string);
Internal Reference @use 'sass:map';$colors: ( 'brand-blue': hsl(195, 85%, 35%), 'action': map.get($colors, 'brand-blue'););
$colors: ( 'brand-pink': hsl(330, 85%, 48%), 'escher': 'brand-pink', 'godel': 'escher', 'bach': 'godel', 'kevin bacon': 'bach',);
@use 'sass:map';@function color($name) { $result: map.get($colors, $name); @if map.has-key($colors, $result) { $result: color($result); } @return $result;}
$colors: ( 'brand-pink': hsl(330, 85%, 48%), 'escher': 'brand-pink', 'godel': 'escher', 'bach': 'godel', 'kevin bacon': 'bach' ('lighten': 20%),);