CSS Hack: Hide from IE
This post was published 5 years 11 months 1 day ago which may make its actuality or expire date not be valid anymore. This site is not responsible for any misunderstanding.As I have been designing small-based, bear-minimum CSS design layouts I have just coded and been done with it. The past six months have been a learning experience and have come to love CSS for what it’s worth. Sometimes, though, designing gets hedious and I have to use hacks; for today, we aim one at Internet Explorer. Please note: This is yet another older piece of writing of mine. As it still probably holds value, I do try to stay away from CSS hacks, but sometimes, they really do come in handy.
There is one hack that I seem to come across more than I really should, but apparently it is one of the most important hacks of today, or should I say, of Internet Explorer? When designing the new layout for Dev-News, I had to use this once. What happened was, Internet Explorer wasn’t spacing bulleted items like ALL the other broswers were; even Opera.
To send different CSS rules to Internet Explorer, I had to use the child selector command, in which Internet Explorer can’t understand (figures). The child selector command involves two elements, one is the parent, and the other the child to the parent. So, the following refers to the child, body, contained within the parent, html:
html>body |
Now let’s take a practical example from Dev-News (now, non-existant website):
#info ul li a { display:block; width:175px; background:url('path_to_image.gif') no-repeat left top; padding:0px 0 0 15px; margin-top:-5px; color:#fff; } html>body #info li a { margin-top:2px; } |
Internet Explorer can’t understand the second CSS rule, due to the hack, so it will ignore it and use the first rule and all other browsers will use the second rule. This has really helped me out with designing a layout. I used to pull my hair out and just let it be. Now that I design compliant websites, I have no room for anything less than perfect – so to speak.
Enjoy, and have fun with your CSS.
September 18, 2007
We’re redesigning our web site from flash based to pure xhtml, css and dom. As you had done before, I was pulling my hair out trying to find a way around some silly IE bugs. Our site still isn’t up, but it should be soon. Thanks for the tip.