CSS hacks
CSS alone is great, but CSS plus standard browser support would be even better. Unfortunately, I doubt that will ever happen, so we hack. I’ve finally limited my browser concerns to the following four: Firefox, Safari, IE7, and IE6 (with IE6 slowly dropping off the list).
As I’m sure you already know, the problem is mainly IE. I had high hopes for IE7, but I have to accommodate it, too. Before IE7 I used the * html hack (or “holy hack” as they call it) for my IE fixes. Since IE7 behaves differently than IE6, but is still not right, I need to attack it as a separate entity. I personally believe conditional comments to be the best alternative for this. It’s ugly, but most hacks are.
Here’s the top of (most of) the sites I build…
<link href="/stylesheets/default.css" media="screen" rel="stylesheet" type="text/css" /> <link href="/stylesheets/safari.css" media="screen" rel="stylesheeet" type="text/css" /> <!--[if IE 7]> <link href="/stylesheets/ie7.css" media="screen" rel="stylesheet" type="text/css" /> <![endif]--> <!--[if IE 6]> <link href="/stylesheets/ie6.css" media="screen" rel="stylesheet" type="text/css" /> <![endif]-->
It’s important to note the order, too. Always put the default styles at the top, then override them with the hacks. Oh, and in the safari.css file, just make sure your styles look like this:
/*\*/
html*ul#content-nav {
top: 128px;
}
.
.
.
html*div#sidebar {
margin-left: -10px;
}
/**/
And remember, in order to override behavior you have to define the selector the same way in your hacks file as it were in the default file due to specificity (ie if you have div p.errors in the default file, you can’t expect p.errors to override it since the latter has a lower specificity).
If you have other suggestions, I’m always interested in better ways to hack CSS.
