微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

“动态”CSS ID名称?如何将它们添加到CSS文件中?

我在一个动态生成的应用程序中有DIV ID,最后有一个ID.例如:< div id =“Vote_score_72”>,< div id =“Vote_score_73”>,< div id =“Vote_score_74”>等等.

如何在CSS文件中编写该ID,以便我可以为其应用样式?

解决方法

除了建议您应该使用类来实现此功能之外(您应该),您可以使用attribute-value-begin-with选择器(这可能不是正式名称):
div[id^=Vote_score] {
    color: #f00;
    /* and so on... */
}

JS Fiddle demo.

编辑添加Quirksmode.orgcompatibility tables for advanced attribute selectors链接.

参考文献:

> CSS3 Attribute-selectors,at Sitepoint.com.
> Attribute selectors,at CSS3.info
> Attribute Selectors,at the Mozilla Developers Network

原文地址:https://www.jb51.cc/css/216157.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。