Suppose I have the following HTML structure:
<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 duplicating CSS code for each color variation like in the example below...
.tocolor-red{
background: red;
}
.tocolor-red::before {
content: "red";
}
... is there a way to create a CSS rule that dynamically assigns the color based on the class name? While exploring attribute selectors and wildcard options, I haven't found a solution that captures the dynamic text from the class.
If regular expressions were applicable in CSS, the rule might resemble something similar to this hypothetical example:
.tocolor-([\w+]) {
background: $1;
}
.tocolor-([\w+]:before {
content: $1;
}