In the last tutorial we discussed the order of precedence of multiple style definitions that could apply to the same element within your web page. This will usually give you what you want because the more specific and closer definition will take precedence and you usually define more specific and closer definitions in order that those definitions override the more general and further away definitions.

You can override this order of precedence for a particular definition and make the particular definition apply even if a more specific or closer definition exists. You do this by making the definition important. Important definitions always take priority over all definitions that are not important. Of course if multiple definitions are all marked as important then the normal order of precedence applies.

So how do we define a definition as important? Well here is an example:

p {font-size:12px !important;}

Note that in this example it is the font-size definition that has been marked as important, any other style definitions that we are applying to the paragraph tag will take their normal order of precedence unless they too are marked as important.

Why would you mark a definition as important? Why not just make sure that there are no more specific or closer definitions that would override it? Well depending on how complicated your stylesheets get you may be able to do just that but if you want to be certain that you don't override an important definition by mistake then you should label it as such.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow