In CSS, you can use an attribute selector with ^ :
div[class^="div-"] ==> Selects all div with the class attribute value starting with "div-"
Example:
div { height: 20px; margin-bottom: 5px; border: 1px solid black; } div[class^="div-"] { border-color: red; }
<div class="div-one"></div> <div class="div-two"></div> <div class="other"></div> <div class="div-three"></div>
Update
As @FreePender says, if the CSS class does not match the class in the attribute value, it does not work. Another solution is to use an attribute selector with * :
div[class*="div-"] ==> Selects all div with a class attribute value containing "div-".
That way, it will also correspond to a CSS class called nodiv-one , but this is not what usually happens.
div { height: 20px; margin-bottom: 5px; border: 1px solid black; } div[class*="div-"] { border-color: red; }
<div class="div-one"></div> <div class="div-two"></div> <div class="other"></div> <div class="myclass div-three"></div>
source share