4 ms·
I have a specific use case for !important - When you have a user stylehseet loaded on top of a website's existing stylesheets. This could happen when: - u
by klochner 16y ago
I have a specific use case for !important -
When you have a user stylehseet loaded on top of a website's existing stylesheets.
This could happen when:
- using something like the UserStyles plugin for firefox
- a website allows users to load custom stylesheets into widgets
(like facebook used to do with their social plugins)
... but I agree that there isn't really a good justification for using the !important declaration if you have full control over stylesheets.
It's about on par with sticking magic constants in your code.
- Hovertruck 16y agoAt Webs (Freewebs once upon a yesterday) we allow people to add custom CSS to their websites that they build on our service. To make things simpler on our end we make user-added rules !important so they don't have to worry about the cascade. That said, probably 98% of our users aren't interested in CSS anyway.
- eschutte2 16y agoI disagree, I have found !important to be the only reliable way to make a print stylesheet override dynamic styles (width, positioning, etc.) applied by a JS UI framework (e.g. ExtJS/Sencha). If someone has a better solution for that please tell me!
- kj12345 16y agoOne option is if you wrap the ExtJS content in a div with an id of "xyz", then find the rule you want to override e.g. in Firebug, you can make a rule in your custom stylesheet that has the same selector as the ExtJS one but prepended with "#xyz ", and your rule will always be more selective and therefore take precedence over the ExtJs rule.
- adamesque 16y agoThis only works if there's an existing style rule to override. The parent post is talking about overriding styles added inline to elements by JS libraries. An inline style will always override a rule in a stylesheet… unless the rule uses !important.