Introduction to SASS
INTRODUCTION TO SASS:
From the previous post, we came to know about BEM methodology. You might feel like naming the class based on BEM would be the toughest one. But this one can be easily resolved by using SASS/SCSS.
What is SASS? Syntactically Awesome Style Sheet (SASS). It is a CSS preprocessor, which adds special features such as variables, nested rules and mixins.
First, what is a CSS preprocessor? It is nothing but a scripting language that extends CSS by allowing developers to code in one language and that will get compiled to CSS. SASS is one of the preprocessors. There are some other preprocessors like LESS, Stylus etc.
- Allow writing clean CSS in a programming construct.
- Reduce repetition
- Create more manageable, reusable, compact style sheets which can be imported and used.
- Faster development time
- Programmatic CSS features.
How to use SASS?
EXTENSIONS:
SASS provides two extensions
- .scss (Sassy CSS) - Implementing with curly braces.
- .sass - implementing without curly braces.
But both should be compiled in the SASS compiler.
How to compile SASS?
I would recommend you to follow either of these following ways:
- Vscode extension - Live SASS compiler.
- By installing node-sass dependency in NodeJS.
IMPLEMENTATION:
This jotting is completely for the novice. To know more about SASS, I strongly suggest you peer through SASS documentation.
1. VARIABLES:
Just like CSS, SASS also allows us to provide variables. DECLARATION: $variable-name
$font-color: #fff;
Body{
color: $font-color;}
2. NESTING:
Nesting helps in reducing the inordinate combinators.
Example:
ul{
li{
Output: (After compilation)
EXAMPLE:
OUTPUT:
.card__title{// some styles}.card__desc{// some styles}
3. PARTIALS:
Partial files are just the snippet of the whole code. This can be imported and used. This is just like a module. Partial files cannot be compiled separately.
DECLARATION: _partials. scss
DECLARATION: @mixin mixin-name{}
Comments
Post a Comment