Special Offer for Blog Visitors — $0.01/m web hosting

Unlimited disk space, unlimited bandwidth, unlimited domain names hosted with FFMPEG support: $7.95/month &mdash 35% discount — $5.17/month
Limited time special offer: Your first month for $0.01 (1 cent only!) — Learn more! — Offer expires on Wednesday 30th of June 2010.

Only CSS hack you’ll ever need, seriously.

Posted: March 1, 2007 at 10:24 pm | (20) Comments

While working on a few of my clients pages, I’ve always used other methods for CSS hacks but mostly using PHP to detect the remote user User-Agent and come up with the specific CSS. Until I’ve discovered this one:

You can actually have IE6 specific lines in CSS, it’s as simple as prefixing them with an underscore. Sure, you might start complaining “STANDARDS!!11!” – If I had to choose from a site that works fine in every browser and standards, I’ll go with the more working one. That’s not all! You can actually have lines that are both IE6 & IE7 specific in CSS by prefixing them with a dot.

So to sum it up, let’s say if I use a left margin that has to be 5px in Firefox/Opera, 6px for IE6 & 7px for IE7 – Here’s how I would do it:

margin-left: 5px; /* Left margin for all browsers, mainly Opera, Firefox, etc. */
.margin-left: 7px; /* Left margin of 7px that can be readable by both IE6 & IE7, now other still think it’s 5 while IE6 & IE7 think it’s 7 */
_margin-left: 6px; /* Only IE6 reads this and changes the value to 6px */

I have to admit I was pretty happy upon discovering this hack; I’ll sure be using it for a while now that I have found a pretty good one.

Do you have any of your own do not need loads of JavaScript and/or PHP code to work? Comment on!

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Comments



Post a comment

Technology Partners