Getting Started with SASS
You may hear a lot about sass and many people told you that when you learn sass it will be your magic wand to style your website dynamically! that’s true and easy to learn come with me …🚶
Why SASS and what is it?
- we need to use logic into our style
- browsers are understanding only normal CSS files
simply this is the problem which SASS came to solve it.
SASS (Syntactically Awesome Stylesheets) is a pre-processor for CSS which introduces to you programming logic in a style dress that’s amazing right!
so you can use sass features and then it compiled to CSS to be understandable through the browsers
How to install SASS?
you could compile your sass code with three ways:
2- Gulp / grunt / webpack … (or any task runner)
- Google it!
3- node sass
let’s dive into some sass features 🔥
Nesting is one of the most important features of sass it let you nest CSS selectors inside each other.
like you observed in the above example CSS with nesting looks like HTML hierarchy which makes more sense, it’s clearly shown that (.child) element is inside (.container) element in HTML DOM tree.
SASS provides us with ampersand sign (&) it could be used as shorthand for parent selectors
Best Practice: DON’T nest more than three levels.
we can also nest properties which have related namespaces such as background, font, and border Nested properties are similar to nested selectors. However, you need to include (:) let’s look at an example
even CSS has its own variables (: root) but still sass variables have the power to go through some logic will cover that later. but for now, how could I define a sass variable?
simply it starts with the dollar sign $ then followed by the variable name.
Best Practice: NAME your variables with descriptive and reusable names such as (primary, secondary, warning…etc) DON’T name it likes its value (blue, red, aboutUsPadding …etc)
Thank you for reading, if you have any comments let me know, please :)
That’s all for today see you soon in my next story …👋