Day 43: grouping layers

Cascade layers can be grouped by nesting layer rules.
If you work on a large style sheet, you might want to create cascade layers to group different types of declarations. In order to give your layers even more structure and control, you can …


This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović

Cascade layers can be grouped by nesting layer rules.

If you work on a large style sheet, you might want to create cascade layers to group different types of declarations. In order to give your layers even more structure and control, you can also group declarations within layers.

Consider the following example. We have a layer for reset styles, base styles, components, and theming.

@layer reset {
body {
margin: 0;
}
}

@layer base {
body {
font-size: 1.6rem;
}
}

@layer components {
p {
border: 1px solid;
}
}

@layer theme {
p {
border-color: red;
}
}

There's nothing wrong with that, but it might make sense to group similar layers. For example, you could group reset and base styles and component and theme styles.

@layer base {
@layer reset {
body {
margin: 0;
}
}

@layer defaults {
body {
font-size: 1.6rem;
}
}
}

@layer components {
@layer structure {
p {
border: 1px solid;
}
}

@layer theme {
p {
border-color: red;
}
}
}

The same rules in terms or prioritization that apply to root layers also apply to nested layers. This adds more complexity to your style sheets, but it also gives you fine-grained control over specificity.

Nesting layer may seem to be overkill, and it probably is for many sites, but it will make more sense once we talk about ordering layers.


This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović


Print Share Comment Cite Upload Translate Updates
APA

Manuel Matuzović | Sciencx (2022-11-23T09:38:54+00:00) Day 43: grouping layers. Retrieved from https://www.scien.cx/2022/11/23/day-43-grouping-layers/

MLA
" » Day 43: grouping layers." Manuel Matuzović | Sciencx - Wednesday November 23, 2022, https://www.scien.cx/2022/11/23/day-43-grouping-layers/
HARVARD
Manuel Matuzović | Sciencx Wednesday November 23, 2022 » Day 43: grouping layers., viewed ,<https://www.scien.cx/2022/11/23/day-43-grouping-layers/>
VANCOUVER
Manuel Matuzović | Sciencx - » Day 43: grouping layers. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/23/day-43-grouping-layers/
CHICAGO
" » Day 43: grouping layers." Manuel Matuzović | Sciencx - Accessed . https://www.scien.cx/2022/11/23/day-43-grouping-layers/
IEEE
" » Day 43: grouping layers." Manuel Matuzović | Sciencx [Online]. Available: https://www.scien.cx/2022/11/23/day-43-grouping-layers/. [Accessed: ]
rf:citation
» Day 43: grouping layers | Manuel Matuzović | Sciencx | https://www.scien.cx/2022/11/23/day-43-grouping-layers/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.