Jump to content

CSS Help override !important?

Is it possible to override the tag important in css? im trying to make a dark theme for a website but the owner has added !important to the background and color of the text.

 

.menu li li a {background: transparent !important; border: none; color: #444 !important;

 

Hardware: Intel I7 4790K 4Ghz | Asus Maximus VII Hero Z97 | Gigabyte 780 Windforce OC | Noctua NH-U12P SE2 | Sandisk Extreme Pro 480GB | Seagate 500Gb 7200Rpm | Phanteks Enthoo Luxe | EVGA Supernova G2 850W | Noctua NF12 | SupremeFX 2014 | Patriot Viper 3 16GB.

Gaming Gear: Cooler Master TK Stealth | Sennheiser PC350SE | Steelseries Rival | LG IPS23L-BN ' 5ms | Philips Brillians 144hz 

Link to comment
https://linustechtips.com/topic/277804-css-help-override-important/
Share on other sites

Link to post
Share on other sites

Well.... You can just remove the !important but I figure that isn't an option. You can also use javascript to remove the important if that's your only option. So, something like

 

<get your element>.style.background = transparent;

 

should work just fine. Alternatively, you can use your own important tag by giving the a tag a higher specificity. That is, give the <a> tags a class of some sort then set the background rule with the important tag there. Becaus e it's more specific about what exactly is being targeted, it will override the old rule

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to post
Share on other sites

Well.... You can just remove the !important but I figure that isn't an option. You can also use javascript to remove the important if that's your only option. So, something like

 

<get your element>.style.background = transparent;

 

should work just fine. Alternatively, you can use your own important tag by giving the a tag a higher specificity. That is, give the <a> tags a class of some sort then set the background rule with the important tag there. Becaus e it's more specific about what exactly is being targeted, it will override the old rule

Thanks (and no its not an option to remove it). The class thing somewhat helped , though everytime i refresh the page with the chrome refresh button (the one beside the url) it removes it, but when i highlight the url and press enter it works -_-

Hardware: Intel I7 4790K 4Ghz | Asus Maximus VII Hero Z97 | Gigabyte 780 Windforce OC | Noctua NH-U12P SE2 | Sandisk Extreme Pro 480GB | Seagate 500Gb 7200Rpm | Phanteks Enthoo Luxe | EVGA Supernova G2 850W | Noctua NF12 | SupremeFX 2014 | Patriot Viper 3 16GB.

Gaming Gear: Cooler Master TK Stealth | Sennheiser PC350SE | Steelseries Rival | LG IPS23L-BN ' 5ms | Philips Brillians 144hz 

Link to post
Share on other sites

Is it possible to override the tag important in css? im trying to make a dark theme for a website but the owner has added !important to the background and color of the text.

 

What you could do is make a new css entry with a more "exact" path, easiest way to do that is adding body infront of the style you want to override:

body .menu li li a { background: #000 !important; } /* This style will override the background of .menu li li a */
Link to post
Share on other sites

So remember that CSS is all about cascading specificity. Anything can be overridden, you just need to be lower down in the stylesheet and/or more specific.

 

In terms of levels of specificity: inline > style block > stylesheet, and ID > class > attribute > element.

 

It even gets pretty specific in how much one is more specific than the other. But for all intents and purposes, the only thing you can't override without manipulating the DOM with JS is a style attribute defined property with an important flag. Here's a great write-up by Chris Coyier.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×