我有以下要素:
<div class="grid">
<div class="col-1">First Col</div>
<div class="col-center-2">Second Col</div>
<div class="col-center-3">third Col</div>
<div class="col-3">third Col</div>
</div>
我想为所有包含"-center-"
字的元素添加类。我如何定义这个选择器?
答案 0 :(得分:6)
您可以使用[attr*=value]
属性选择器
div[class*="-center-"] {
color: red;
}
&#13;
<div class="grid">
<div class="col-1">First Col</div>
<div class="col-center-2">Second Col</div>
<div class="col-center-3">third Col</div>
<div class="col-3">third Col</div>
</div>
&#13;