I'm currently learning sass/scss and i'm documenting my progress here till I finish learning
Here are the list of things i've learnt so far;
- variables in scss
- Partials
- Nesting and indentation
- Mixins
I'm currently learning scss on Youtube by FreeCodeCamp.
Here's the link ππΎ - Sass Tutorials for Beginners
To check out sass documentation ππΎ - Sass documentation
SCSS stands for Sassy Cascading style sheets. Itβs a preprocessor that is useful for writing css in a better and more effective way.
I say itβs a preprocessor that solves problems that arises with css.
Some benefit of scss includes;
-
Writing clean code by eliminating the repetition of code
-
Solving problems faced with css such as organizing code.
-
Writing programmable css.
Variables are a way to store data so they can be referenced easily. To store variables in scss, we use the $ sign as opposed to the sign -- used in css
e.g ππΎ
`$variable: code;
`
-
Partials are used to make the css code less bulky and more sectioned. Rather than writing all our code with one file, we can create different files for different sections and write our code. This makes our code more organized and readable.
-
We however have to name those files differently so that the scss compiler can identify those files as partials. We also have to import the files to the main scss file.
-
To name the partial files, we simply place an underscore _ in front of the name of the file and end it with .scss
Functions are like calculators. You give it a value/input and it runs the set of instructions placed in it, using the input you gave and finally, returns the result/output.
Here's a code snippet ππΎ - `scss @function nameOfFunction (input) { @return code; }
`
Mixins are like utility classes. They are used to store repetitive codes.
Here's a code snippet ππΎ
`` `scss
@mixin nameOfMixin { repetitive code };
`` `
In order to use the repetitive code in scss, we use @include
and the name of of the mixin.
@extend
is used to copy the properties on an element and paste those properties to another element.
Nesting helps in scss because you donβt have to repeat yourself. Interpolation is simply a way to concatenate code. In SCSS, we use #{}
Here's a code snippet ππΎ
.parentElement {
code;
.parentElement child element {
code;
}
}
&
This is a parent selector in scss so you donβt repeat your code when referencing parent elements.