A CSS preprocessor called SASS (Syntactically Awesome Style Sheets) adds more sophisticated capabilities to standard CSS, such as variables, nesting, mixins, partials, and imports. It makes developing CSS code easier to read and maintain. We will examine some of the main components of SASS/SCSS.
Variables: Let you save variables under a name, such as fonts, colors, or any other CSS value. This makes your styles easy to manage and is handy for reuse across your CSS.
Nesting: Allows you to arrange your CSS selectors in a manner consistent with the HTML visual hierarchy.
Mixins are a useful technique for building adaptable, reusable styles since they are reusable code segments that have the ability to take arguments.
SCSS code
// SCSS syntax $primary-color: coral; $padding: 10px; @mixin flex-center { display: flex; align-items: center; justify-content: center; } .container { background-color: $primary-color; padding: $padding; .content { @include flex-center; background-color: darken($primary-color, 10%); } } button { @include flex-center; margin: $padding; background-color: lighten($primary-color, 10%); } |
The basic color that is used by the button and.container classes is defined by the variable $primary-color.
An element can be made to flex and center by using the mixin flex-center definition. It is present in buttons and in.content.
When.content is nested inside a container, nesting is displayed inside the container, signifying that.content is a child of the container.
A CSS preprocessor called SASS (Syntactically Awesome Style Sheets) adds more sophisticated capabilities to standard CSS, such as variables, nesting, mixins, partials, and imports. It makes developing CSS code easier to read and maintain. We will examine some of the main components of SASS/SCSS.
Variables: Let you save variables under a name, such as fonts, colors, or any other CSS value. This makes your styles easy to manage and is handy for reuse across your CSS.
Nesting: Allows you to arrange your CSS selectors in a manner consistent with the HTML visual hierarchy.
Mixins are a useful technique for building adaptable, reusable styles since they are reusable code segments that have the ability to take arguments.
SCSS code
// SCSS syntax $primary-color: coral; $padding: 10px; @mixin flex-center { display: flex; align-items: center; justify-content: center; } .container { background-color: $primary-color; padding: $padding; .content { @include flex-center; background-color: darken($primary-color, 10%); } } button { @include flex-center; margin: $padding; background-color: lighten($primary-color, 10%); } |
The basic color that is used by the button and.container classes is defined by the variable $primary-color.
An element can be made to flex and center by using the mixin flex-center definition. It is present in buttons and in.content.
When.content is nested inside a container, nesting is displayed inside the container, signifying that.content is a child of the container.
Copyrights © 2024 letsupdateskills All rights reserved