Example 1 works:
HTML:
<div class="items">
<div class="item">item 1</div>
<div class="prefix-item-suffix">item 2</div>
<div class="item">item 3</div>
</div>
CSS:
div[class^="prefix"][class$="suffix"] {
color: red;
}
Example 2 doesn't:
HTML:
<div class="items">
<div class="item">item 1</div>
<div class="multiple prefix-item-suffix classes">item 2</div>
<div class="item">item 3</div>
</div>
CSS:
div[class^="prefix"][class$="suffix"] {
color: red;
}
Example 2 has multiple classes so CSS approach stops working. In real time project the multiple classes will be random except the one targeted in between them, the value between prefix-the_dynamic_value-suffix will also be random, how to target that with other classes inside same element? Because example 1 approach doesn't work.
item red.. then class selector would be.item.red, without a space between.. then it has to have at leastclass="item red".. is just basic css[attribute^='value']and[attribute$='value']just selects HTML tags that begin with the attribute value and ends with the attribute value, respectively. That does not mean that it will see if aclassattribute value within your attribute begins with or ends with the value. Just usediv.prefix-item-suffix{}and create other classes to do other things.