What's wrong with my conditional comment?

173 views Asked by At

I have IE 11. I'm making the following conditional comment for my html:

    <!--[if (lt IE 9)]>
        <div style="background-color: black; width: 200px; height: 400px;"></div>
    <![endif]-->

Then I'm trying to check if it works via IE built-in emulation, setting both document mode and user agent string options to IE 8 or IE 7. The block in the comment is not displayed, but the comment disappears at the same time from html.

Is it something wrong with the code or with emulation?

2

There are 2 answers

3
way2vin On

Remove brackets

<!--[if lt IE 9]>
     <div style="background-color: black; width: 200px; height: 400px;"></div>
 <![endif]-->

is enough

There is a great article by Paul Irish, conditional-stylesheets-vs-css-hacks-answer-neither it is worth reading for sure.

0
Oliboy50 On

I'm copying Teemu's comment in this answer as community wiki, because it's what I was looking for since few days... and I think this is the right answer here.

IE11 doesn't support conditional comments, not even in any emulating mode. Among some other old APIs, support for conditional comments was dropped in IE10, and more legacy APIs are obsoleted in IE11. In IE11 these changes mostly reflect to emulating modes too. But don't worry, your conditional comments are still working in real IE<9 : )

THANK YOU Teemu !

By the way, there's a software wich understands IE conditional comments while IE 11 can't anymore : it's IETester. Will be really useful now...