Daniel Williams Daniel Williams - 13 days ago 5
CSS Question

Applying rules to multiple classes using a * match

My class names generate dynamically and I'm trying to apply styling to them using a kind of preg_match. Is something like this possible?

<style>
.*_class {
border: 1px solid red;
}
</style>

<div id="a_class">a</div>
<div id="b_class">b</div>
<div id="c_class">c</div>

Answer

You need to use attribute selectors for this.

[class$="_class"] {

}

The above says, anything with a class that ends with _classs should be selected. For more information, see Attribute Selectors.

Comments