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ć
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.