我在应用程序中有动态生成的 DIV id,末尾有一个 ID。例如:<div id="vote_score_72">
, <div id="vote_score_73">
, <div id="vote_score_74">
等等。
如何在 CSS 文件中写入该 id 以便对其应用样式?
进一步建议您应该使用类来实现此功能(并且您should), you can,而是使用 attribute-value-begins-with 选择器(这可能不是正式名称):
div[id^=vote_score] {
color: #f00;
/* and so on... */
}
JS 小提琴演示 http://jsfiddle.net/davidThomas/rR4aT/.
Edited to add a link to the
Quirksmode.org http://www.quirksmode.org/'s
compatibility tables for advanced attribute selectors http://www.quirksmode.org/css/contents.html#t31.
参考:
-
CSS3 属性选择器,位于 Sitepoint.com http://reference.sitepoint.com/css/css3attributeselectors.
- 属性选择器,位于 CSS3.info http://www.css3.info/preview/attribute-selectors/
-
属性选择器,位于 Mozilla 开发者网络 https://developer.mozilla.org/en/CSS/Attribute_selectors.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)