CSS which takes precedence, inline or the class?

前端 未结 4 1618
后悔当初
后悔当初 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:44

    The order of precedence with CSS is as follows:

    1. !important (this is a bit hackish though but it is the only way to override an inline style. Try to avoid using this unless really necessary). Example: p {color: blue !important; }
    2. Inline, such as

      CSS is awesome

      .In this example, the class is ignored if the redText class declaration has already tried to define the property of color:. Other properties can still be honored though.
    3. Internal styles - those written inside the