Go to DotNetFunda.com
 Welcome, Guest!  
LoginLogin  
Take a break and be productive! read technical jokes.
 Skip Navigation Links Home > Articles > CSS > Conditional statement in CSS

All Articles | Submit Article |

Conditional statement in CSS

 Posted on: 10/15/2007 1:15:11 PM by SheoNarayan | Views: 3705 | Category: CSS | Level: Advance | Print Article
You must have came across some .css issues related with the browser behavior. Some of the styles that works in IE doesn't work in FireFox.

In that situation you need to write conditional code for both browsers.

 Get Career Counseling  
DotNetFunda.Com brings you a FREE Career Counseling section where you can ask any type of career related question. Ask now!

Below is the sample code that demonstrate how to write conditional statement tin CSS.


<html>
<head>
<title>Conditional CSS</title>
<style type="text/css">
body
{
color:blue;
}
</style>
<!--[if IE 7]>
<style type="text/css">
body {
background-color:red;
}
</style>
<![endif]-->
</head>

<body>
<p>
SHEO NARAYAHN
</p>
</body>
</html>


If you copy-paste above code as an .html file and browse into IE 7, you will get the background color of the page as red and color of the text as blue but if you will browse the same page in FireFox, the background property of the body tag will not be applicable and it will be default (white) while you will see the color of the text as blue as you were seeing into IE 7.

This is because the color of text has been specified as default style while the background is written as conditional statement.

Thanks
------------------------------------------------------------------
Edited: Found a detailed article on this topic later on, see here
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/ccomment_ovw.asp

Interesting?   Bookmark and Share


About Sheo Narayan

Experience:6 year(s)
Home page:http://sheonarayan.myfunda.net/
Member since:Tuesday, July 08, 2008
Biography:Throughout 1st in all educational exams.
Major qualifications: HDCS, ADCA, MCA, MCTS
Location: Hyderabad, India
 Latest post(s) from SheoNarayan

   ◘ Ensuring button is clicked only once, Confirmation and Please wait message for ASP.NET Form posted on 7/3/2009 3:34:15 PM
   ◘ Setting up Start Options in Visual Studio and Visual Web Developer posted on 6/28/2009 7:53:02 AM
   ◘ Website vs Web Application - Embedded resources posted on 6/23/2009 10:10:20 PM
   ◘ Adding removing xml attribute from XML File in .NET posted on 6/21/2009 12:55:43 AM
   ◘ Working with Themes in ASP.NET posted on 6/8/2009 12:13:10 PM


 Submit Article

About Us | Contact Us | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
All rights reserved to DotNetFunda.Com. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
(Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher)