Css !important | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Css !important

How can I change a tag property in css if in html the property is written with “!important” inline?

19th Oct 2019, 5:51 PM
Lilit Yeghiazaryan
Lilit Yeghiazaryan - avatar
5 Answers
+ 3
By indicating one or more elements before the element you're selecting, the rule becomes more specific and gets higher priority: https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
19th Oct 2019, 7:56 PM
Calviղ
Calviղ - avatar
+ 3
If your HTML has inline css styling with "!important" and you want control, remove the "!important". E.g. - External css file has this .myfontstyle { font-size:2em; font-weight:bold; color:#fff;} Inline style has this <p style="font-size:1em!important ;">some text</p> Your paragraph text will be 1em. The !important attribute takes higher priority. Removing it, you can use a class in your external css stylesheet to style the paragraph as you want. <p class="myfontstyle">some text</p> Your font size should now be 2em. But if some parent element takes control of your font size and your external css font-size of 2em does not work, you can add the !important attribute to font-size in external css to take back control. .myfontstyle { font-size:2em!important ; font-weight:bold; color:#fff;} Your font size will be 2em now if the paragraph element <p> had inherited a different font size from a parent element . Hope that makes sense. Sounds tricky when I read it back.
19th Oct 2019, 11:04 PM
Xyenia 🦉
Xyenia 🦉 - avatar
+ 2
thank you Xyenia
20th Oct 2019, 8:15 AM
Lilit Yeghiazaryan
Lilit Yeghiazaryan - avatar
+ 1
Based on specificity, that's exactly high as you can go. So you have to modify the html file http://www.standardista.com/css3/css-specificity/?sa=X&ved=2ahUKEwjso5qa_qjlAhXJp48KHQoZAmgQ9QF6BAgLEAI
19th Oct 2019, 6:53 PM
Lingesan S
Lingesan S - avatar
0
inline !important has highest value I need some hack for resolve this
19th Oct 2019, 7:49 PM
Lilit Yeghiazaryan
Lilit Yeghiazaryan - avatar