Sass 1

Sass (Syntactically Awesome StyleSheet) is a CSS-compatible pre-processor extension, developed in 2006.

In React, we npm install sass to transpile a sass file into CSS, due to the browser being unable to read sass.

Global and local variables are declared outside/inside selectors.

Sass variables are imperative, any change will only affect the following variables, while CSS variables are declarative, and any change in value will affect the previous uses too.

//Sass variables can store strings/numbers/booleans/colors/lists
//Any variables will affect only the selectors below it
$primo: red;

.coral{ 
  color: $primo; 
}

.coral1{ 
  $primo: green;      //use !global to reset the global variable
  color: $primo ; 
}
sass style DOM element

Sass can nest properties names if they start with the same word.

We can @import external sass files, usually to separate the sass variables file from the sass selectors file.

SCSS mixin, include and extend

The @mixin and @include directives create and set blocks of sass properties to use on selectors.

Both - and _ are considered the same digit on mixin names.

We can also use it to shorten vendor prefixes.

@mixin and @include sass

The @extend directive passes a set of properties between selectors.

Export Sass to javascript and CSS color-mix()

We :export sass variables to javascript:

The Sass file doesn't exist during runtime, so we need CSS :root variables to change the Sass variables dynamically.

chevron-rightDynamically change a CSS property string and set it on sass.hashtag

We can't interpolate var(--css) variables in Sass.

We modify sass variables (passed from CSS) by editing the property value "string".

The color-mix(in colorspace, color1 %, color2 %) is a CSS functional notation to mix color values

The default percentage values are 50% and its return value can be passed as var().

Opposite color-mix() and hsl 50% contrast colors

Set bootstrap variables with Scss

We use Sass to modify npm install bootstrap variables.

custom Bootstrap.css

Sass variables are used as fallback values, and are converted to CSS during compilation, without the need for CSS root{} properties.

We can only edit sass variables when used in a selector, so we use them to overwrite bootstrap props (after removing the css bootstrap import from App.js).

scss variables with js edit
chevron-rightJs editing bootstrap selectors with sass variableshashtag

We can var() and calc() sass variables on style properties.

We need to re-set the sass property in the js for it to work.

hsl() single sass variable colors edited on js

1

1

Last updated