∅ 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]-->

#2 by satish

08:55 on 9 December 2008

I was going nuts as to why the conditional statement always ended in a comment line...
You made my day..
Thanxx amillion..

#3 by Christiane

18:52 on 17 September 2009

The last option by keed worked for me as well. The two blank lines made the cond. comment lines disappear. Thanks a lot!

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

Waiter Rant book cover

I haven't posted many book reviews since I relaunched this weblog. Not that I didn't want to, or was at a loss. Quite the contrary. I have a number of books I would { have } like{ed} to talk...

Music

Parov Stelar | Coco CD cover

Parov Stelar is an Austrian musician and DJ located in Linz, to who's music I have really taken to since discovering his album “Shine” last year. Like Waldeck, his music is smooth and silky, and entices you to listen...

Pictures

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


© 2000-2009 David Roessli | v4.1 | as valid xhtml and css as possible | hosted by pair Networks | RSS feeds.