Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How are selectors and selectors nested in sass?


Asked by Lana Lawson on Dec 06, 2021 FAQ



Sass lets you nest CSS selectors in the same way as HTML. Notice that in Sass, the ul, li, and a selectors are nested inside the nav selector. Because you can nest properties in Sass, it is cleaner and easier to read than standard CSS.
Next,
Sass allows us to nest selectors hierarchically by writing them inside the code blocks of other selectors. In SCSS we nest between the open and close curly braces. In indented Sass we nest with an extra indentation for each level.
Keeping this in consideration, If you want to do more with your nested style rules than just combine them in order with the descendant combinator (that is, a plain space) separating them, Sass has your back. See the parent selector documentation for more details. You can use interpolation to inject values from expressions like variables and function calls into your selectors.
In addition,
When nesting with combinators we can place the combinator on the outer selector line, the inner selector line, or on its own line. Sass provides us with the special & parent selector that refers to the current nesting’s parent and can be used as name replacement.
Consequently,
1 You should use a double class selector. This problem is a perfect example of nesting option in Sass. You can read all about that here kolosek.com/nesting-in-less-and-sass