Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: !important not overriding other rules [duplicate]

I am trying to change the font color in my navigation bar. I use bootstrap and my own stylesheets. I want my font to be red, so I'm trying to override every other rule with the help of !important (other things failed as well). But the color stays grey. Those are the computed values on my element from chrome developer tools:

  • color: hsl(0, 0%, 60%);
  • .navbar-inverse .navbar-brand - #999
  • a - #428bca
  • a:-webkit-any-link - -webkit-link
  • nav - red !important
  • body - #333

How is it possible that !important gets overriden by styling with class selector and how to make my font red?

(answer is that !important only overrides styles on the same element you apply it to. It doesn't make the element's descendants inherit from it) - from comments.

like image 393
lakesare Avatar asked Nov 01 '22 22:11

lakesare


People also ask

Can Important be overridden in CSS?

There are two ways you can override an ! important tag in CSS. You can add another CSS rule with an ! important tag and use a selector with a higher specificity.

How do I override another CSS rule?

To override the CSS properties of a class using another class, we can use the ! important directive. In CSS, ! important means “this is important”, and the property:value pair that has this directive is always applied even if the other element has higher specificity.

Which stylesheet has highest priority in CSS rules overriding?

Any inline stylesheet takes the highest priority. Therefore, it will override any rule defined in <style>... </style> tags or rules defined in an external style sheet file.

How do I get rid of important CSS?

You should be able to do this by increasing specificity on your mobile css file and adding an ! important value to this new value in the mobile stylesheet. yeah, increasing specificity will do it, but this should be done if there is no other ways to do it.


1 Answers

Try this:

.navbar .navbar-nav>li>a {
    color: red;
}
like image 112
Gofilord Avatar answered Nov 12 '22 10:11

Gofilord