views:

217

answers:

2

Has anyone been able to succesfully use the IE CSS hack #IEroot? I stumbled upon it from this article but it doesn't seem to work for me.

I'm trying to fix/hack the inline styling bug to produce li inline blocks

#featured li {
 margin:0px;
 padding:0px;
 width:317px;
 height:310px;
 display:inline-block;
 border-left:1px #bdbdbd solid;
}
#IEroot #featured li {
 display:inline;
}

Any help would be greatly apperciated, thanks.

A: 

I'm using a beta of IE8, and the example on the page that you are referring to does not work. The live demo also doesn't seem to take IE8 in count.

These kinds of hacks are clever, but I'd advice you to stay away from it.

Whenever you encounter differences between browsers, there are always alternative ways to do the same thing in such a way that it works for all browsers.

I've made more websites full of CSS than I can count, and I never ever resort to browser-specific code, especially not the kind that exploits bugs in specific versions of browsers. They solve a tiny problem today, but give you twice the headaches tomorrow, and are a bitch to maintain.

If you insist on using such a hack, make sure to add a comment like this:

/* >>>>>>> BUTT-UGLY BROWSER HACK! FIX ME!!!!! <<<<<<<< */
#IEroot #featured li {
    display:inline;
}

:-)

Wouter van Nifterick
That explains why I'm not seeing it either - I have IE8 as well (forgot I downloaded it..)
Chance
I wish they'd quit fixing hacks designed to fix their damn bugs.
Chance
+3  A: 

IT DOES WORK, exactly as described, EVEN in IE8, and is actually a pretty smart CSS hack to get around IE specific bugs.

You MUST swap out the DOCTYPE line for a REAL DOCTYPE though first.

Here is the code from the link, tweaked to be a working sample.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
<html>
<head>
<style>
/* all browsers make border red */
#IE { border : 2px solid red; }
/* all browsers see this, but only IE thinks #IEroot exists as an element and makes border blue */
#IEroot #IE { border-color : blue; }
</style>
</head>
<body>
<!--[if IE]>
<div id="IEroot">
<![endif]-->
<p id="IE">This browser is IE. (red in all, blue in IE)</p>
<p id="notIE">This browser is not IE.</p>
<!--[if IE]>
</div>
<![endif]-->
</body>
</html>
scunliffe
Yes. This works just fine in IE with the doctype: <ul id="featured"><li>one</li><li>two</li></ul>
Traingamer
Nice one on the doctype. I still see it as Bad Practice have the design of a site rely on a bug in IE though.I'm sure that this specific problem can be solved in a really simple and elegant alternative way in a matter of minutes.Lists don't work? use spans, or whatever does the trick.
Wouter van Nifterick