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. Creating PDF’s on the fly using PHP & FPDF
  3. New Changes at Google AdWords
  4. Backlinks on Free high page rank directories
  5. What FFMPEG-PHP can do and how to use the most out of it

Comments



Post a comment


What our clients are saying — Read More →

My Auto responder website was a nightmare for me, I was always kicked out from web hosting companies simply because I email too much, my responder was double optin and there were no spam issues. But with you, things changed, I am relaxed and can concentrate on my main business. Also you have a very responsive technical support that really helps answer my questions.


Trevor L.
Awards — View More →

Technology Partners