How does Chrome dev tools generate CSS selectors?

后端 未结 2 807
醉酒成梦
醉酒成梦 2021-01-13 22:11

When adding a new style rule for an element, the selector that Chrome generates contains the entire hierarchy instead of just the class name.

For example:

         


        
2条回答
  •  日久生厌
    2021-01-13 22:47

    There are multiple reasons this could be happening. Without knowing the exact attributes being taken its hard to tell. Also seeing your css would help as well.

    To the best I understand you are asking why when you it takes its parent div and parent body attributes as well.

    This could be because it is itself a child of body and div

    Another logical explanation here is a working example on jsfiddle

    Depending on your elements you could have something conflicting. In the case of my example the !important tag is added giving its color attribute precedence over the span class But in the next line it applies fine.

    
          
    I am being applied
    I am helper but i am not red
    body > div > span { color: red !important; } .helper { color: green }

提交回复
热议问题