CSS which takes precedence, inline or the class?

前端 未结 4 1607
后悔当初
后悔当初 2020-12-14 19:06

My website has a stylesheet defined in the header as style.css with a selector:

.myClass {background:#000;}

Now my div looks like:

4条回答
  •  独厮守ぢ
    2020-12-14 19:56

    Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number three has the highest priority:

    1. Browser default
    2. Embedded and external stylesheets. Later has precedence over earlier. There IS NOT any inherent difference between embedded and external.
    3. Inline style (inside an HTML element)

    Source (Edit: of original incorrect information, since corrected both here and there): w3schools

    W3schools explains a lot about CSS and also goes through and shows examples of most things you can do with CSS. Always a good resource if you have questions about something. (Edit: debatable, they were the source of the original wrong answer.)

提交回复
热议问题