得到混淆有关类的优先级在CSS中,我知道在最后添加的类具有最高优先级,但在这里我的例子 我以为我错了我动态地添加类div,但类不能正常工作Css类的优先级,当添加动态类
<p>Click the button to add the "mystyle" class to DIV.</p>
<script>
function myFunction() {
document.getElementById("myDIV").classList.add("mystyle","hello");
}
</script>
<style>
.hello{
background-color: blue;
}
.mystyle {
background-color: red;
}
</style>
为什么div显示红色而不是蓝色?
可能的重复http://stackoverflow.com/questions/17727739/precedence-of-multiple-classes-defining-color-property-being-set-by-claclaration – Harry
你回答自己的问题:'class added at **最后**具有**最高优先级**' - 您的最后一个类是'.myStyle',所以... – somethinghere
我的意思是说在使用类名时这样的'
'@somethinghere –