Note that there are some explanatory texts on larger screens.

plurals
  1. POTargeting IE Using Conditional Comments and Just One Stylesheet
    primarykey
    data
    text
    <p><strong>Updated: [See third technique at the bottom of this question regarding Paul Irish's technique!]</strong></p> <p>I'm wondering what the web devs out there think about these two methods? Which is best? Considerations for both?</p> <p><strong>Method 1:</strong> </p> <p>Single CSS File for all styles, with conditional comments in wrapper divs to apply specific IDs to HTML.</p> <p>CSS</p> <pre><code> /*** For IE 7 and up ***/ #ie7andup #anyelement { border-color : blue; } </code></pre> <p>HTML</p> <pre><code>&lt;!--[if gte IE 7]&gt; &lt;div id="ie7andup"&gt; &lt;![endif]--&gt; &lt;!--[if IE 6]&gt; &lt;div id="ie6only"&gt; &lt;![endif]--&gt; &lt;!--[if IE 5.5000]&gt; &lt;div id="ie5-5only"&gt; &lt;![endif]--&gt; &lt;!--[if lt IE 5.5000]&gt; &lt;div id="ie5-01only"&gt; &lt;![endif]--&gt; &lt;div id="anyelement"&gt;a box with some content&lt;/div&gt; [... more page content ...] &lt;!--[if IE]&gt; &lt;/div&gt; &lt;![endif]--&gt; </code></pre> <p>(via <a href="http://www.positioniseverything.net/articles/cc-plus.html" rel="nofollow">http://www.positioniseverything.net/articles/cc-plus.html</a>)</p> <p><strong>Method 2:</strong></p> <p>Separate IE stylesheets, with conditional comments including those CSS files.</p> <pre><code>&lt;link href="main.css" rel="stylesheet" type="text/css"&gt; &lt;!--[if IE 7]&gt; &lt;link href="ie7.css" rel="stylesheet" type="text/css"&gt; &lt;![endif]--&gt; &lt;!--[if IE 6]&gt; &lt;link href="ie6.css" rel="stylesheet" type="text/css"&gt; &lt;![endif]--&gt; &lt;!--[if IE 5]&gt; &lt;link href="ie5.css" rel="stylesheet" type="text/css"&gt; &lt;![endif]--&gt; </code></pre> <p>(via <a href="http://reference.sitepoint.com/css/conditionalcomments" rel="nofollow">http://reference.sitepoint.com/css/conditionalcomments</a>)</p> <p>For targeting all the IE's and fixing their issues. Wouldn't the first method be cleaner in your CSS, and simplify it? Or does it make sense to have separate CSS files for IE?</p> <p>I'd love to see some links to other references/articles defending one method over the other. I see most people using the latter.</p> <hr> <p><strong>Update - Check out this technique from Paul Irish!:</strong></p> <p>This could be even better. How about this way? That way with Modernizer you could have your one stylesheet have specific section for IEs within it -</p> <p><a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/" rel="nofollow">http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/</a></p> <p>Thoughts on that?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload