• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

5.2. !important

The !important property enables Web authors to increase the “weight” applied to a certain rule, ensuring that it overrules any other CSS properties that might otherwise be specified. The !important property is useful in situations where you want to ensure that a certain formatting style is always applied to a document.

Listing 5.2. !important

<html>
<head>
<title>!important</title>
<style>
p {color: blue !important}
p {color: red}
p.fuchsia {color: fuchsia}
body {font-size: 34px; font-weight: bold}
</style>
</head>
<body>
<p>
This line of text should be in blue.
</p>

<p style="color: red">
This line of text should also be in blue, even though it is set to 
red.
</p>

<p class="fuchsia">
This line of text should also be in blue, even though it is set to 
fuchsia.
</p>

<p style="color: red !important">
This text should be in red, as it is set to !important. This 
specific setting overrides the global !important reference for 
this page, following proper cascading rules.
</p>

</body>
</html>


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint