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.

                Now, we get into our case ”SASS”.

                Why SASS?
  • 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

  1.  .scss  (Sassy CSS) - Implementing with curly braces.
  2.  .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:

                        nav{
                                ul{
                                     list-style-type: none;
                                     li{
                                         margin-top: 10px;
                                         margin-bottom: 10px;                                    
                                       }
                                }
                        }

                            Output: (After compilation)

                            nav ul{
                                    list-style-type: none;
                            
                            nav  ul li{
                                    margin-top: 10px;
                                    margin-bottom: 10px;   
                            }
                                    
                               BEM Methodology can be applied easily using SCSS/SASS.

                                  EXAMPLE:

                                            .card{
                                                     &__title{
                                                                // some styles
                                                     }
                                                      &__desc{
                                                               // some styles
                                                     }
                                             }     

                                     " & => Parent selector"                       

                                  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                                       

                    4. MIXINS:
                                Mixins help in reusing the same codes. This reduces the lines of code that we are typing. This can be done by using the keyword @include mixin-name.

           DECLARATION: @mixin mixin-name{}


                   5. EXTENDS:                                 Extends are simply the inheritance. These codes can be inherited and used for some other components.                        DECLARATION: @extend class-name
                    
                     This post is just for letting you know about the existence of the SASS concept. I firmly recommend you to read the documentation. This concept may look difficult at the initial stage. But practice makes perfect. So practise a lot. Have you enjoyed reading this post? Leave your thoughts in the comment section. To boost up your computer knowledge, I put forward you to get along with our posts.
                    
                       
                                                

Comments

Popular posts from this blog

MULTIMEDIA

Exploring The Hidden Internet

SKINPUT TECHNOLOGY