CSS selector cascading/specificity not working as expected

落花浮王杯 提交于 2019-12-01 23:01:17
MarcinJuraszek

It's because first style matches the element and the second one is inherited from it's parent.

Specificity only plays its role when two selectors matches the same element. Not when it comes to style inheritance from parent elements.

You can see that on really simple example:

#myID {
  color: red;
}

p {
  color: green;  
}
<div id="myId">
  <p>Some text</p>
</div>

Even though #myId is more specific text is green because p selector matches that element directly and therefor is more important than color inherited from div.

To make p elements inside .button white you need:

.hud > .main > .button p {
    color: #fff;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!