匹配所有具有以特定字符串开头的类名称的元素
问题描述:
是否可以对类名以CSS3中的特定字符串开头的元素使用通配符"?
Is it possible to use a "wildcard" for elements having a class name starting with a specific string in CSS3?
例如:
<div class="myclass-one"></div>
<div class="myclass-two></div>
<div class="myclass-three"></div>
,然后神奇地将以上所有div
设置为红色:
and then magically set all the above div
s to red in one go:
.myclass* { color: #f00; }
答
以下方法可以解决问题:
The following should do the trick:
div[class^='myclass'], div[class*=' myclass']{
color: #F00;
}
添加了大卫建议的通配符(*
)