Learn About SASS

Introduction

 
It is an extension to css.
 
It helps us write more flexible CSS styles.
 
It makes use of variables, functions, conditional statements, etc.
 
Files can be split like modules, making it easy for large projects.
 
Statements of SASS is not understandable to the browser, so it needs to be converted/translated to css file.
 
It is written in Ruby.
 
Sass is like a programming language, so you must know programming fundamentals, like variables, function, conditional statements, etc.
 
You should know CSS.
 

Start using Sass

 
Install ruby and PrePros and start with SASS.
 
Open application Prepros.
 
Add/Drag your project folder.
 
Learn About SASS
 
You can see your folder name ‘Project’ with different folders ‘css’, ‘img’, and ‘scss’.
 
Open your editor (VS code) and open the same folder.
 
Create a file style.scss under scss folder.
 
Learn About SASS
 
Open prepros application and set the settings as below,
 
Learn About SASS
 
Select your scss file and do the settings as given in the picture.
 
Make sure to check the ‘Auto Compile’.
 
Once you save your file ‘*.scss’, it will compile your sass file and generate the css file defined on our output path.
 
Also, a popup will be shown once you save your file from editor.
 
Learn About SASS
 
Now,
 
Open style.scss and add the content below. 
  1. .rule{  
  2.     color: red;  
  3.     a{  
  4.         color: blue;  
  5.         span{  
  6.             color:pink;  
  7.         }  
  8.     }  
  9. }  
Save the file you have created and open style.css.  You will see the below content that is generated, once you save the scss file.
  1. .rule {  
  2.   color: red; }  
  3.   .rule a {  
  4.     color: blue; }  
  5.     .rule a span {  
  6.       color: pink; }  
Create a file index.html under project folder.
 
Add contents below. 
  1. <html>  
  2.     <head>  
  3.         <link href="css/style.css" rel="stylesheet"/>  
  4.     </head>  
  5.     <body>  
  6.         <div class="rule">  
  7.             <a href="#">This is a link. <span>text under span text.</span></a>  
  8.         </div>  
  9.     </body>  
  10. </html>  
Open index.html in the browser and you can see your class and styles applied, as pre style.css generated by style.scss.
 
Open the index.html in the browser and see the applied styles.