Go to DotNetFunda.com
  Welcome, Guest!  
LoginLogin  
{ Submit resources and get monthly gifts !!! }
Submit: Article | Interview Question | Joke | Question | Link || Search  
 Skip Navigation Links Home > Articles > Conditional statement in CSS

All Articles | Post Articles

Conditional statement in CSS

 Posted on: 10/15/2007 1:15:11 PM by SheoNarayan | Views: 1142 | 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.

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


- Hide Code

<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
Bookmark and Share

About Sheo Narayan

Experience:6 year(s)
Home page:http://sheonarayan.blogspot.com/
Member since:Tuesday, July 08, 2008
Biography:--
Throughout first in the all educational exams.
Major qualifications: HDCS, BCA, ADCA, MCA
Locations: Hyderabad, India
 Latest post(s) from SheoNarayan

   ◘ How to pass a value from User Control to the Page posted on 7/8/2008 1:06:59 PM
   ◘ Implementing Custom Paging in ASP.NET with SQL Server 2005 posted on 6/25/2008 7:45:44 PM
   ◘ Checking / UnChecking all checkboxes of the page dynamically in a single click posted on 6/7/2008 7:51:55 AM
   ◘ Getting connectionStrings / appSettings values from web.config file posted on 6/3/2008 5:52:37 AM
   ◘ How to create an ASP.NET website using Visual Web Developer? (Pictorial View) posted on 5/23/2008 9:58:25 AM



Question: Why to use www.dotnetfunda.com google search?
Answer: This search has been especially optimized to search technical articles. You may find to-the-point results in comparison with other search.
Google
About Us | Contact Us | 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.