Gary Haran.com


Ultimate Cross Browser CSS Hack

Posted in Programming by gary.haran on the May 1st, 2007

With Internet Explorer 7 finally around the corner it’s safe to say that IE5 is going to be less and less of a worry. However because Microsoft had so many bugs in IE6 now fixed in IE7 we now have to take those into account when designing proper CSS.

Because conditional comments is great when you don’t mind having multiple css files I wanted a better approach, one that would allow all CSS to be in a single file so I can separate css files for other reasons than cattering to the browser du jour.

Here’s a simple hack that allows you to cater to over 90% of browsers out there.

#divName{ padding-top: 2px;/* Safari, FF, Opera */ #padding-top: 1px;/* IE7 */ _padding-top: 1px;/* IE6 */ }

Yes that’s 3 lines instead of a single one. At least it’s all in the same file.

One Response to 'Ultimate Cross Browser CSS Hack'

Subscribe to comments with RSS or TrackBack to 'Ultimate Cross Browser CSS Hack'.

  1. heri said,

    on June 21st, 2007 at 4:02 pm

    this is ugly - sorry.

    so what would you do for opera mobile, safari iphone….

    i hate css hacks. and what i hate more is ie. what i am doing these days i just drop ie.

    i have a bug with montrealtechwatch for ie7 but dont want to install the browser.

Leave a Reply