Only CSS hack you’ll ever need, seriously.

Posted: March 1, 2007 at 10:24 pm | (23) 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:

1
2
3
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!

Related posts:

  1. Few CSS tricks you may not know
  2. SEO Tips: For how many keywords should you optimize your web page?
  3. Web Hosting for Dummies: What is Web Hosting?!
  4. Top 5 new (and cool!) features in PHP5 that you probably haven’t heard of
  5. Custom PHP configuration from cPanel (php.ini, .htaccess)

Comments



Post a comment


What our clients are saying — Read More →

When I found Vexxhost I was pleased because I had located a Canadian web hosting company that was priced competitively, and offered everything I needed. I didn't realize just how excellent it would turn out to be! I have watch in amazement as feature after user-friendly feature is added to my service, the control-panel interface keeps improving (and it was very very good to begin with), the service never slows down, and the price stays the same excellent rate. I have come to appreciate that Vexxhost is not just the best web hosting company in Canada, Vexxhost is quite likely the best web host in the world. I realize that sounds like hyperbole, but it's not - seriously, if you don't believe me, try it yourself. Thanks, guys!


Gabriel Abney
Awards — View More →

Technology Partners