Open In App

Sass | At-rules

At-rules are simply some CSS statements that instructs the CSS how to behave in particular conditions. They start with an “@” sign, followed by an identifier and ends with a semicolon (in case of SCSS), or the next CSS statement (in case of SASS), depending upon the Sass syntax used. 

Syntax:






@identifier(rule);

Below is this list of Sass at-rules that are used:

Sass also provides certain behavior for simple CSS at-rules like: @charset and @namespace. They can contain interpolation, and they can be nested in the style rules. Some of them, like @media and @supports, also allows Sass to be used directly in the rules itself even without using interpolation.



A lot of Sass’s extra functionality comes in the forms of these at-rules.

Example code:




.error
  border: 1px green
  background-color: black
 
  &--serious
    @extend .error
    border-width: 3px

This would give the following CSS output:

.error, .error--serious {
  border: 1px green;
  background-color: black;
}
.error--serious {
  border-width: 3px;
}
Article Tags :