What is SASS (Syntactically Awesome Style Sheet)?
As the stylesheets are getting more complex and the files are getting larger, SASS is here to help us to get rid of these problems. SASS is a framework, which helps developers to reduce CSS code.
Why SASS ?
SASS helps to minimize the code complexity of CSS and can be well organized.
The code duplication can be removed if you use SASS.
Primary Requisites to start SASS
- Need to know the basics of CSS
- Knowledge in HTML
SASS supports two types of syntax mainly. They are SCSS and SASS.
The main difference is the braces{ } and the semicolon.The table, given below, shows the difference between the two syntax-
| SASS | SCSS |
| .message border: 1px solid #ccc; padding: 10px; color: #333 . |
message { border: 1px solid #ccc; padding: 10px; color: #333; } |
I will follow SCSS syntax throughout my blog
In order to have the minimized code or pre processed code, SASS supports the features, given below-
- Variables
The first thing which comes to your mind is when you hear the variable is about the variables in C# or JavaScript or any programming language because we use the variables to assign the values. SASS variables are also used for the same purpose. You can assign hex values, strings of text, colors, numbers etc.
You can create a variable, using $ symbol.
Example - $body-color: red;
Nesting
XML /HTML document has a nice code hierarchy, where the code is nested accordingly, based on the tags through which the code looks good, easy to understand and maintain. Don’t you think, why can’t we have the same for CSS? Yes, SASS made it possible. We can nest the CSS rules easily in an efficient way.
The example is given below-
| SCSS | CSS |
| footer { .navbar-inverse { Background-color:lightgoldenrodyellow; } .navbar-nav { float: left; margin: 0; > li > a { padding-top: 15px; padding-bottom: 15px;}}} |
footer .navbar-inverse { background-color: lightgoldenrodyellow; } footer .navbar-nav { float: left; margin-top: 0px; } footer .navbar-nav > li > a { padding-top: 10px; padding-bottom: 15px; } |
Join the conversation! Your thoughts help the community grow.