Solved

Conditional CSS

Posted on 2011-02-24
3
218 Views
Last Modified: 2012-05-11
Hi,

I have the following code:

<html>

      <head>

            <style type="text/css">

            body
            {
                   [if IE] background-color : blue;
                   [if Gecko] background-color : red;
            }

            </style>

      </head>

      <body>

            <form name="form1">

            </form>

      </body>

</html>

It is not working as expected in IE 6.0. Can you please FIX this ?

Thanks
0
Comment
Question by:milani_lucie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Expert Comment

by:LAMASE
ID: 34974336
I don't know if IE6 supports that kind of styling... it seems that you need to install something for have that styles working
http://www.conditional-css.com/usage

try this, calling different styles in head section

<!--[if !IE]><!-->  
  <style type="text/css">@import '/media/css/c-css.php?b=nonIE';</style>  
<!--<![endif]-->  
<!--[if IE 6]>  
  <style type="text/css">@import '/media/css/ic-css.php?b=IE&v=6';</style>  
<![endif]-->  
<!--[if gte IE 7]>  
  <style type="text/css">@import '/media/css/c-css.php?b=IE&v=7';</style>  
<![endif]-->  

Open in new window


Keep in mind that you can make everything in a common css file, then include different "patch" css files for different browsers.
0
 
LVL 4

Accepted Solution

by:
LAMASE earned 500 total points
ID: 34974360
Sorry, I pasted the wrong example
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="ie7.css" />
<![endif]-->
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]-->

Open in new window

0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 34974436
@LAMASE's examples are correct.  The conditional statements are in the HTML file and can control loading of additional CSS files but the conditional statements do Not work inside the CSS declarations or files.  In addition, only IE will recognize them.  Using [if Gecko] has no effect, Mozilla and Webkit browsers do not recognize such things.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question