Let's say I have the following HTML:
<div class="tocolor-red"> tocolor </div>
<div class="tocolor-blue"> tocolor </div>
<div class="tocolor-green"> tocolor </div>
<div class="tocolor-yellow"> tocolor </div>
Instead of having to repeat CSS code like the snippet below for each color...
.tocolor-red{
background: red;
}
.tocolor-red::before {
content: "red";
}
... is there a way to write a CSS rule that captures the color from the css class instead? For the sake of due diligence, I've looked up attribute selectors already and I've noticed that there are a number of ways you can use wildcards in css already. However, I haven't found anything that would allow me to capture the wildcard text and as part of a rule.
If regex worked for CSS, the rule would look something like this:
.tocolor-([\w+]) {
background: $1;
}
.tocolor-([\w+]:before {
content: $1;
}