Google News
logo
Sass Interview Questions
* SASS means Syntactically Awesome Style sheets
* Sass is an extension to CSS
* Sass is a CSS pre-processor
* Sass is completely compatible with all versions of CSS
* Sass reduces repetition of CSS and therefore saves time
* Sass is free to download and use
Sass was initially designed by Hampton Catlin and developed by Natalie Weizenbaum (November 28, 2006). After its initial versions, Weizenbaum and Chris Eppstein have continued to extend Sass with SassScript, a scripting language used in Sass files.
Stylesheets are getting larger, more complex, and harder to maintain. This is where a CSS pre-processor can help.
 
Sass lets you use features that do not exist in CSS, like variables, nested rules, mixins, imports, inheritance, built-in functions, and other stuff.
 
Example :
/* define variables for the primary colors */
$primary_1: #a2b9bc;
$primary_2: #b2ad7f;
$primary_3: #878f99;

/* use the variables */
.main-header {
  background-color: $primary_1;
}

.menu-left {
  background-color: $primary_2;
}

.menu-right {
  background-color: $primary_3;
}

 

A browser does not understand Sass code. Therefore, you will need a Sass pre-processor to convert Sass code into standard CSS.
 
This process is called transpiling. So, you need to give a transpiler (some kind of program) some Sass code and then get some CSS code back.
* It allows writing clean CSS in a programming construct.
 
* It helps in writing CSS quicker.
 
* It is superset of CSS which helps designers and developers work more efficiently and quickly.
 
* As Sass is compatible with all versions of CSS, we can use any available CSS libraries.
 
* It is possible to use nested syntax and useful functions such as color manipulation, mathematics and other values.
* It takes time for developer to learn new features present in this pre-processor.
 
* If more number of people working on the same site, then will use the same preprocessor. Some people use the Sass and some people use the CSS to edit the files directly. So it will become difficult to work with site.
 
* There are chances of losing benefits of browser's built-in element inspector.
SassScript supports seven main data types :

* Nulls (e.g; null)
* Colors (blue, #04a3f9)
* Numbers ( eg; 1,5 ,10px)
* Strings of texts ( g., “foo”, ‘bar’, etc.)
* Booleans (true or false)
* Maps from one value to another (g., ( key 1: value1, key 2: Value 2))
* List of values, separated by space or commas (g., 1.5em, Arial, Helvetica etc.)
The main differences between SCSS and SASS :
 
* SASS is like a CSS preprocessor. It has the extension of CSS3. SASS is derived from another preprocessor known as Haml (HTML abstraction markup language).

* SASS contains two types of syntax: "SCSS" is the first syntax, and it uses the extension of .scss. Indented syntax or "SASS" is the other syntax, and it uses the extension of .sass

* You can covert the valid CSS document into SASS by simply change the extension from .CSS to .SCSS.

* SCSS is fully CSS compatible. It provides CSS-friendly syntax to closing the gap between SASS and CSS. SCSS is called Sassy CSS.
Nesting is combining of different logic structures. Using SASS, we can combine multiple CSS rules within one another. If you are using multiple selectors, then you can use one selector inside another to create compound selectors.
SASS supports placeholder selector using class or id selector. In normal CSS, these are specified with "#" or ".", but in SASS they are replaced with "%".
* It needs a filename to import function.
*
It facilitates you to extend the CSS import rule. To do this you need to enable import of Sass and SCSS files.
* It can merge the all the imported files into a single outputted CSS file.
* It is used to virtually match and mix any file.
* It provides document style presentation better than flat CSS.
* It facilitates you to keep your responsive design project more organized.

Example : 
@import "test.css";
@import "css/test.css";
@import url("http://example.com/css/test.css");

 

We can easily select the parent selector by using the & character. It specifies where we should insert the parent selector.
Sass supports standard CSS comments /* comment */, and in addition it supports inline comments // comment :
 
Sass Example : 
/* define primary colors */
$primary_1: #a2b9bc;
$primary_2: #b2ad7f;

/* use the variables */
.main-header {
  background-color: $primary_1; // here you can put an inline comment
}

 

There are 5 types of operations :
 
* Number Operations : It allows for mathematical operations such as addition, subtraction, multiplication and division.

* Color Operations : It allows using color components along with arithmetic operations.

* Boolean Operations : You can perform boolean operations on Sass script by using and, or and not operators.

* List Operations : Lists represent series of values which are separated using commas or space.

* String Operations
The @mixin directive is used to define the mixins that include the variables and argument optionally after the name of the mixin.
 
Sass @mixin Syntax :
@mixin name {
  property: value;
  property: value;
  ...
}

 

As a shortcut for writing @mixin and @include directives, we can use = for @mixin directive and + for @include directive. It requires less typing, makes our code simpler and easier to read, and saves our time.
In SASS, we can easily define an element in a variable and interpolate it inside the SASS code. It is useful when we keep our modules in separate files.
As the name suggests, the compressed CSS style takes the least amount of space compared to all other CSS styles. It provides whitespaces only to separate selectors and newlines at the end of the file.
LESS is a dynamic style sheet producing language. It is a CSS preprocessor that extends CSS with dynamic behavior. It allows for variables, mixins, operations, and functions and runs on the server-side and client-side both.
The procedure to create and store a LESS file is similar to creating/storing a CSS file. You can create a new LESS file with a .less extension or rename the existing .css file to a .less file. You can write LESS code with existing CSS code. You should follow the best practice of creating it inside ~/content/ or ~/Styles/ folder.
When you run the LESS.js in an HTML5 browser, it uses local storage to cache the generated CSS. However, the developers cannot see the changes they made instantly. In order to see the changes you made instantly, you can load program in development and watch mode by using following JavaScript :
<script type= "text/javascript">  
   less.env = "development " ;  
   less.watch () ;  
</script>
  
<script type= "text/javascript">  
   less.env = "development " ;  
   less.watch () ;  
</script>​

 

  
There are two types of mixin arguments : 
 
Keyword Arguments : It is used to include arguments in the mixins. The arguments which are named can be passed in any order and the default values of argument can be omitted.
 
Variable Arguments : Variable arguments are used to pass any number of arguments to mixin. It contains keyword arguments passed to the function or mixin.
DDRY-ing out a Mixin function splits into two parts : the static part and dynamic parts.
 
The static Mixin contains the pieces of information that would otherwise get duplicated and the dynamic Mixin is the function that the user going to call.
The @error is used to display the SassScript expression value as fatal error and @debug detects the errors and displays the SassScript expression values to the standard error output stream.
Pros :
* Sass is easy to learn especially for them who has a background of Python, Ruby or Coffescript and place using functions, writing mixins
* CSS can be easily converted to Sass
* Throughout the project, you don’t have to repeat similar CSS statements using @extend attribute
* It allows to define variables that are usable throughout the entire project
* It keeps your responsive project more organized

Cons :
* Requires time to learn new features of preprocessor before using
* You may not be able to use the built-in element inspector feature of the browser
* Troubleshooting can be difficult
* red
* green
* blue
*
hue
* saturation
* hsvhue
* saturation
* hswalue
* alpha
* luma
* luminance
The Sass @media directive is used to set style rules to different media types. It supports and extends the @media rules. This directive can be nested inside the selector SASS but the main impact is displayed to the top level of the style sheet. For example :
 
h2{    
    color: red;    
   }    
.style{    
    width: 450px;    
      @media screen and (orientation: portrait){    
         width:180px;    
         margin-left: 90px;    
      }    
}​

 

   
The Sass @at-root directive is a collection of nested rules that are used to style block at the root of the document.

For example :
 
 h2{    
   color: blue;    
    background-color: pink;    
   @at-root {    
         .style{    
             font-size: 20px;    
             font-style: bold;    
             color: violet;    
         }    
    }    
}

 

The SASS @extend directive is used to share a set of CSS properties from one selector to another. It is a very important and useful feature of Sass. It allows classes to share a set of properties with one another. It makes your code less and facilitates you to rewrite it repeatedly.

For example :
 .message    
  border: 1px solid #ccc    
  padding: 10px    
  color: #333    
.success    
  @extend .message    
  border-color: green    
.error    
  @extend .message    
  border-color: red    
.warning    
  @extend .message    
  border-color: yellow 

 

Sass @debug directive is used to detect the errors and display the Sass Script expressions values to the standard error output stream.

For example :
$font-sizes: 10px + 20px;    
   $style: (    
     color: #bdc3c7    
   );    
.container{    
    @debug $style;    
    @debug $font-sizes;    
 }