What are the priorities among CSS selectors

前端 未结 9 1589
日久生厌
日久生厌 2020-11-27 22:27

CSS Question: If two different selectors apply to an element, who wins?

I know this shouldn\'t happen, but I want to tweak a legacy application, and the CSS is getti

9条回答
  •  半阙折子戏
    2020-11-27 22:47

    you have to find #no of id =A ,#no of class =B and #no of tag =c in the selector

    ABC with higher value wins.

    .wrapper .title  p {  
      //some other rules
    }
    
    A=0 B=2 C=1 =021
    
    \#foo {
      // some more rules
    }
    
    A=1 = 100
    
    .bar .head div li{
      // some more rules
    }
    
    
    A=0 B=2 C=2 =022
    

    100>022>021

    so #foo wins

提交回复
热议问题