∅ the empty set

Spaces matter in IE 7's conditional statements

Internet Explorer 7

This might not be news for you, but it came as a surprise to me when I recently tested a website under Internet Explorer 7 and discovered that nothing showed up, although it displayed normally under IE 6.

The culprit was the conditional statement in the head section eventhough it targeted browsers lower than version 7. Internet Explorer conditional statements are proprietary code that enable a web designer or developer to feed specific code to a specific version, or range of versions, of Internet Explorer. It is very handy to add IE specific css or javascript for example.

I use it to tweak layout related problems with IE by overriding or modifying certain css properties of the main css stylesheet or rewriting part of the DOM. Browsers other than IE treat the statement as a comment, and thus ignore its content.

This specific conditional comment lacked a space after the opening comment element (or had a space to much before the closing comment element) and IE 7 commented out all the page as a result. Interestingly, the reverse isn't true, and it's only this specific configuration that creates this issue.

This configuration doesn't work (unbalanced space on closing comment element):

<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="/css/iewin.css" />
<![endif] -->

But these do:

<!-- [if lt IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="/css/iewin.css" />
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="/css/iewin.css" />
<![endif]-->
<!-- [if lt IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="/css/iewin.css" />
<![endif] -->

Although IE 6 doesn't suffer from this issue, I felt this quirk was worth mentioning.

Ø permalink: http://www.davidroessli.com/logs/2007/05/spaces_matter_in_ie_7s_conditi/


Reponses to “Spaces matter in IE 7's conditional statements”

#1 by keed

10:50 on 5 November 2007

Try also:

<!--[if IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="" />
<![endif]-->

Post a comment


Previous: Hot in Geneva

Next: Embracing iTunes Plus, or from LPs to MP4a, or some 32 years of music


About

Hello, my name is David Roessli. I am a freelance web designer and developer based in Geneva, Switzerland.

This weblog is an nth attempt to solve my multiple online personalities and weblog/rss feeds burnout issues. (more)

Words

Transcending CSS book cover

This is the kind of book I love to discover. The last time I got so excited by a book on CSS was when I read Jeffrey Zeldman's Design with Web Standards back in 2003. Unfortunately, it doesn't happen...

Music

Belleruche | Turnable Soul Music CD cover

Another smooth discovery I made while browsing Asa' "Listeners also bought" section of iTS. Belleruche is a well-crafted mix of bass & drums with a sensual, smoky, sexy female vocalist, together with funky guitar moments. Pure soulful jazz under...

Pictures

Check out my latest Flickr ramblings. Mostly day to day cameraphone pictures stolen here and there.


© 2007 David Roessli | v2.0 | valid xhtml and css