匹配所有具有以特定字符串开头的类名称的元素 [英] Match all elements having class name starting with a specific string
本文介绍了匹配所有具有以特定字符串开头的类名称的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以对类名以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;
}
添加了大卫建议的通配符(*
)
这篇关于匹配所有具有以特定字符串开头的类名称的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文