What are the priorities among CSS selectors

前端 未结 9 1568
日久生厌
日久生厌 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:51

    CSS stands for Cascading Style Sheets. This means that rules apply to elements in a cascading way. It's perfectly normal that different selectors apply to an element. Thinks, for example, to the following:

    Test

    The following rules would affect to the "foo" element:

    .wrapper {
      //some other rules
    }
    
    #foo {
      // some more rules
    }
    
    .bar {
      // some more rules
    }
    

    Rules for priorities can be found here.

    I always advise to use the Firefox "firebug" plugin. It will show you exactly which properties are evaluated for a specific element and why, emphasizing overrides during the cascade.

提交回复
热议问题