!important declaration line is very useful in the css. You are easy understanding following important declaration code.
Browsers supporting it: IE5.5+, Firefox 1+, Safari 3+, Chrome 1+.
Example #1:
CSS Code:
#csscls p {
color: blue;
}
...
#csscls p {
color: red;
}
HTML CODE:
<div id="csscls">
<p >This paragraph text text text text </p>
</div>
Results:
Red text
///////////////////////////////////////////////////////////////////////
Example #2: With !important
CSS Code:
#csscls p {
color: blue !important;
}
...
#csscls p {
color: red;
}
HTML CODE:
<div id="csscls">
<p >This paragraph text text text text </p>
</div>
Results:
Blue text
/////////////////////////////////////////////////////////////////////////////////
Example #3:
CSS Code:
#csscls p {
color: blue !important;
}
#csscls p {
color: red !important;
}
HTML CODE:
<div id="csscls">
<p >This paragraph text text text text </p>
</div>
Results:
Red text
/////////////////////////////////////////////////////////
Example #4:
CSS Code:
#csscls p {
color: blue !important;
}
HTML CODE:
<div id="csscls">
<p style="color:green;">This paragraph text text text text </p>
</div>
Results:
Bule text
////////////////////////////////////////////////////////////
Example5 #
CSS Code:
#csscls p {
color: blue !important;
}
HTML Code:
<div id="csscls">
<p style="color:green !important;">This paragraph text inline style</p>
</div>
Results:
Green text
/****************************/
Another Example :
Without important declaration in Style css
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Without important declaration in Style css </TITLE>
<style type="css/text">
.colabc { background-color: green }
</style>
<BODY>
<div class="colabc" style="background-color:red">Take that!</div>
</BODY>
</HTML>
Output / Result
Text color in red
With important declaration in Style css
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> With important declaration in Style css </TITLE>
<style type="css/text">
.colabc { background-color: green !important}
</style>
<BODY>
<div class="colabc" style="background-color:red">Take that!</div>
</BODY>
</HTML>
Output / Result
Text color in green
Browsers supporting it: IE5.5+, Firefox 1+, Safari 3+, Chrome 1+.
Example #1:
CSS Code:
#csscls p {
color: blue;
}
...
#csscls p {
color: red;
}
HTML CODE:
<div id="csscls">
<p >This paragraph text text text text </p>
</div>
Results:
Red text
///////////////////////////////////////////////////////////////////////
Example #2: With !important
CSS Code:
#csscls p {
color: blue !important;
}
...
#csscls p {
color: red;
}
HTML CODE:
<div id="csscls">
<p >This paragraph text text text text </p>
</div>
Results:
Blue text
/////////////////////////////////////////////////////////////////////////////////
Example #3:
CSS Code:
#csscls p {
color: blue !important;
}
#csscls p {
color: red !important;
}
HTML CODE:
<div id="csscls">
<p >This paragraph text text text text </p>
</div>
Results:
Red text
/////////////////////////////////////////////////////////
Example #4:
CSS Code:
#csscls p {
color: blue !important;
}
HTML CODE:
<div id="csscls">
<p style="color:green;">This paragraph text text text text </p>
</div>
Results:
Bule text
////////////////////////////////////////////////////////////
Example5 #
CSS Code:
#csscls p {
color: blue !important;
}
HTML Code:
<div id="csscls">
<p style="color:green !important;">This paragraph text inline style</p>
</div>
Results:
Green text
/****************************/
Another Example :
Without important declaration in Style css
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Without important declaration in Style css </TITLE>
<style type="css/text">
.colabc { background-color: green }
</style>
<BODY>
<div class="colabc" style="background-color:red">Take that!</div>
</BODY>
</HTML>
Output / Result
Text color in red
With important declaration in Style css
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> With important declaration in Style css </TITLE>
<style type="css/text">
.colabc { background-color: green !important}
</style>
<BODY>
<div class="colabc" style="background-color:red">Take that!</div>
</BODY>
</HTML>
Output / Result
Text color in green
good
ReplyDelete