What is the "! mportant" in CSS? [duplicate]

0

Several times I've seen this attribute or property (I do not know exactly how to rate it), but I still do not realize:

  • What is the need to use it;
  • In order for you to serve yourself;
  • When you use it.

h4, .texto{
  
      color:white !important;
      text-align: center;
      font-size: 40px;
  
}
    
asked by anonymous 28.01.2017 / 06:50

1 answer

1

It serves to override the css already assigned to the element, Example:

.corAzul{
background-color: blue !important; 
}

.corVerde{
background-color: green; 
}
<input type="text" style="background-color:red;" class="corAzul"/>
<input type="text" style="background-color:red;" class="corVerde"/>

As you can see in the example I have the classes corAzul and corVerde being blue as important and green not and inline I put to be red, In input1 it brings blue and in green it considers inline, So since you have both styles equal to the same element with ! Important you tell the browser which one to consider.

    
28.01.2017 / 07:23