Daniel Williams Daniel Williams - 1 year ago 97
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?

.*_class {
border: 1px solid red;

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download