【发布时间】:2015-07-20 22:02:14
【问题描述】:
我有一个 CSS 类,我们称之为myclass
.myclass {
background-color: 'green';
}
动态添加到页面上的元素。这很好用,但是当有更具体的选择器时,例如: input[type='text'] ,它的 background-color 属性被使用。现在,我需要编写更具体的选择器,虽然我不知道将在 DOM 中的哪个元素上添加这个类,所以这将覆盖该元素上的所有其他选择器。也许我可以从这样的事情开始:
html body .myclass {
background-color: 'green';
}
还是有更好的方法?
【问题讨论】:
-
试试
.myclass { background-color: 'green' !important; } -
我的回答是相关的:stackoverflow.com/a/19399881/1317805
-
@JamesDonnelly ,我不能使用 ID,但是重复 css 类选择器真的很有趣,我会试试看!
-
顺便说一句,
background-color: 'green'语法错误,它必须不带引号,而且这个工具非常有用 - josh.github.io/css-explain 再一个链接 - csswizardry.com/2014/07/hacks-for-dealing-with-specificity
标签: html css css-specificity