得到混淆有關類的優先級在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 –