alt131 - 9:29 am on Sep 22, 2011 (gmt 0)
Hi Efe, thanks for posting the code - is that the code that is now working - or the earlier code that wasn't working as desired? The reason I ask is because I'd like to explore margin collapsing, and "working" code won't expose the issue.
Not quite - the cascade assigns a "weight" to rules, and !important gives a rule more "weight", so usually it will be applied unless your own rules ahve a greater weight or specificity.
So the function of !important is overriding default stylesheet settings then. Doesn't that apply automaticly when you define your own values?
Again, not quite. A reset will only "reset" rules that have a lesser weight. Useful reading on this is the cascade (section 6.4) [w3.org]. A reset relies on having greater weight, usually because it is applied last. However, !important will mostly retain greater weight, so won't be over-ridden.
I've seen it in use before but never understood it. Isn't that the same function of reseting css (http://meyerweb.com/eric/tools/css/reset/?
I think this is an interesting question (thanks), and for me the key to understanding is recognising they are different things: !important affects the weight of a rule, while the idea behind a reset is that it will over-ride earlier rules because of it's place in the cascade.
!important is very powerful, but be cautious if using it - it can be difficult to over-ride and the most common technique is to start using very specific selectors. But that creates very specific code, and that can create real maintenance issues.