Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you put IE conditionals in the css file or in the html file?

Tags:

css

I tried putting the IE conditional in a CSS file, but that didn't appear to work. Is there a construct for CSS so you can tell it to use this background color if the browser is IE? I also couldn't find anything on if then else conditionals, does it exist? Can someone provide an example.

like image 604
Xaisoft Avatar asked Feb 20 '09 19:02

Xaisoft


2 Answers

The IE conditional(s) go in the HTML, and should be used to include an additional CSS file that will overwrite CSS as needed for IE hacks.


Example:

<head>
    <style type="text/css">
    @import url(/styles.css);
    </style>
    <!--[if lte IE 6]>
        <link rel="stylesheet" type="text/css" href="ie6.css" />
    <![endif]-->
</head>
like image 164
Chad Birch Avatar answered Sep 20 '22 23:09

Chad Birch


I've taken my cue from jQuery and use my conditional formatting to create container elements

<body class="center">
<!--[if IE 5]><div id="ie5" class="ie"><![endif]-->
<!--[if IE 6]><div id="ie6" class="ie"><![endif]-->
<!--[if IE 7]><div id="ie7" class="ie"><![endif]-->
<!--[if IE 8]><div id="ie8" class="ie"><![endif]-->
    <div class="site text-left">

    </div>
<!--[if IE]></div><![endif]-->
</body>

then I can put the conditional information in css like such

.site { width:500px; }
.ie .site { width:400px; }
#ie5 .site { width:300px; }
like image 32
bendewey Avatar answered Sep 20 '22 23:09

bendewey