How to Target CSS Styles to Internet Explorer 6 and IE7
TweetThis article has been updated on January 30, 2009. Please see the bottom of this article for the gory details.
Today, for the umpteenth time in the past month, I found myself coding a design to work around bugs in the Internet 6 and 7 web browsers. I had found and posted a link to a great site on our Resources pages, on the HTML and CSS page, and realized that it should be posted on the blog as well.
Basically, to target a style so that only Internet Explorer 6 and 7 web browsers will respond, add an asterisk before the definition like this:
#some-style {
…
top: 45px;
*top: 55px; /*hack for IE6 and IE7 browsers*/
…
}
If you want to target a style so that only Internet Explorer 6 will respond, add an underline before the definition, like this:
#some-style {
…
top: 45px;
_top: 55px; /*hack for IE6 only*/
…
}
This tip is from Last Child, an excellent resource on CSS. This tip is really cool because it is lightweight and standards-compliant browsers like Firefox and Safari will ignore the hacks.
The real problem with CSS hacks, besides the fact the Microsoft browsers are so poorly coded in some ways, is future maintenance of your CSS code. At the least, you should put a comment next to any CSS element that is targeted solely to an IE browser. That way you can quickly find these hacks in the future and make changes on the day, one hopes, Microsoft releases a truly web standards compliant browser. One that requires no hacks. At worst, do not go for complicated hacks whenever possible. They’re more difficult to maintain going forward.
UPDATE (Jan 30, 2009): Please ignore what I describe above because it is non-optimal for solving this particular problem (how to make IE browsers conform to standards). Instead, the best approach to code around bugs in Microsoft browsers is to use conditional comments, as described in this absolutely brilliant SitePoint article, Internet Explorer Conditional Comments, and used on sites like this one if you select View > Source and study the page code. Also, if useful, here is the official Microsoft page about conditional comments.
Unlike the approach above, where you put into one CSS file all your styles for all browsers, conditional comments let you create separate stylesheets for separate browsers. Therefore, when IE6 goes away, for example, you simply remove the conditional comment that delivers your IE6-specific stylesheet. You don’t have to touch any styles in any other stylesheet, or hunt down every last style you tweaked for IE6 browsers. Plus your CSS code will be pristine with no hacks.
So I apologize I steered people wrong up to this point. Hopefully the links to conditional comments will more than make up for the error. And please let me know if you find a better way to solve this problem (if you’re a gazillionaire, perhaps you could buy Microsoft and cancel all their web browser software development).
URLs:
http://reference.sitepoint.com/css/conditionalcomments
http://msdn.microsoft.com/en-us/library/ms537512.aspx
http://www.last-child.com/ie7-hacks/
http://www.redwrangler.com/resources/html-and-css.php#iebugs
- Latest Stories
- Popular Articles
- Popular Stories
- How to Pick an Online ECommerce Shopping Cart: 6 Carts Reviewed
- How to Code HTML Email Newsletters
- How To Create An Editorial Process To Publish Web Content
- How to Protect Your Website Images
- How To Do Basic Search Engine Optimization for Web Pages
- How To Easily Edit DNS Zone Files To Configure Email Servers
- How To Evaluate and Hire Programmers, Without Being A Programmer
- Browse all articles
- How To Create An Editorial Calendar to Publish Blogs, Facebook Fan Pages, Twitter, and Email Newsletters
- WorkingPoint Easily Manages Your Business Accounting
- Email Newsletters Get More Social
- How to Add Background Images to Email Newsletters
- Contrast is King in Design
- New Search Site Aggregates Personal Data
- Quick and Dirty Remote User Usability Testing
- The Social Media Landscape in Charts
- Resources: CSS Frameworks, PSD to HTML, Text Editors
- How To Code HTML Email Newsletters (All New Version)
- How To Code HTML Email Newsletters (All New Version) - 309,955 views
- How To Easily Edit DNS Zone Files To Configure Email Servers - 31,315 views
- How To Create An Editorial Calendar to Publish Blogs, Facebook Fan Pages, Twitter, and Email Newsletters - 24,306 views
- How to Protect Your Website Images - 23,243 views
- How to Pick an Online ECommerce Shopping Cart: 6 Carts Reviewed - 20,409 views
- B2B Buyers Have Very High Social Media Participation - 16,783 views
- The Big, Bad List of Search Engine Optimization Questions to Ask - 16,719 views
- Who’s Your Coding Buddy? - 16,694 views
- How to Deal with Internet Explorer 6 (IE 6) - 16,693 views
- About tweetCC and Why Licensing Your Twitter Tweets Matter - 16,664 views
Great Online Communities to Explore
Community MX - Web Design with Adobe twist
IxDA - Interaction Design
Boagworld - Web Design
SitePoint - Web Design, Coding
The Content Wrangler - Content, Content, Content
@TypeTweets - Twitter for Type-o-philes
Webmasterworld - Web Design
Get the Email Newsletter: Keep Up To Date
Stories, links, and more emailed to you every few weeks!

Connect With Us Online
We provide low-cost, how-to internet marketing information for individuals, businesses, and groups, as well as the people who support them. Learn more