![]() |
VOOZH | about |
Sass (Syntactically Awesome Style Sheets) is a CSS preprocessor that enhances standard CSS by introducing features like variables, nesting, imports, mixins, and inheritance, all while maintaining compatibility with all CSS versions.
Example: File name index.html
Variables: Variables can be used to store CSS values that may be reused. To declare a variable in SASS, the '$' character is used. For eg, $v_name.
$fs: 30px;
$bgcolor: #00ff40;
$pd: 100px 350px;
#dl {
font-size: $fs;
color: $bgcolor;
padding: $pd;
}This fig. shows the same code:
👁 ImageAfter compiling the CSS code, save it in file by style.css.
#dl {
font-size: 30px;
color: #00ff40;
padding: 100px 350px;
}👁 ImageNesting: Nesting in SASS allows CSS rules to be nested within each other, which follows the same visual hierarchy of HTML. For eg. CSS property can be used to the <li> tag nested inside the div tag.
$fs: 30px;
$bgcolor: #00ff40;
#col2: #ff0066e1;
$pd: 100px 350px;
#dl {
font-size: $fs;
color: $bgcolor;
padding: $pd;
li {
color: $col2;
}
}👁 ImageAfter compiling the CSS code save it file by style.css.
#dl {
font-size: 30px;
color: #00ff40;
padding: 100px 350px;
}
#dl li {
color: #ff0066e1;
}👁 ImageOutput:
👁 ImageMixins:Mixins helps to make a set of CSS properties reusable i.e. it saves one code and use it again and again. It can be included in other CSS rules by using the @include directive.
Example: This example describes the use of @mixin & @include.
$fs: 30px;
$bgcolor: #00ff40;
#col2: #ff0066e1;
$pd: 100px 350px;
@mixin font_style() {
font-family: sans-serif;
font-size: $fs;
color: blue;
}
#dl {
@include font_style();
padding: $pd;
}👁 ImageAfter compiling the CSS code becomes:
#dl {
font-family: sans-serif;
font-size: 30px;
color: blue;
padding: 100px 350px;
}👁 ImageThe output of the web page:
👁 ImageExample: Mixins can also take variables as arguments. The values are passed while including them in the CSS rules.
$fs: 30px;
#col2: #ff0066e1;
$pd: 100px 350px;
@mixin font_style() {
font-family: sans-serif;
font-size: $fs;
color: blue;
}
@mixin list_style($size, $color) {
font-size: $size;
color: $color;
}
#dl {
@include font_style();
padding: $pd;
li {
@include list_style(20px, red);
}
}👁 ImageThe compiled CSS code:
#dl {
font-family: sans-serif;
font-size: 30px;
color: blue;
padding: 100px 350px;
}
#dl li {
font-size: 20px;
color: red;
}👁 ImageFinal Output:
👁 Image