CSS Hacks
Working with browsers and CSS
Thursday, August 06, 2009 2:26 PM
Playing with css
Every now and then you have to work with CSS and making things look identical in all the browsers can be quite difficult. Here is n easier way to achieve this if you are having problems getting that single browser to work they way you need it to.
What you can you use is the underline (_) , and the dash (-) hack as I like to call it. First what you ahve to do is declare what you want all browsers to read first just as you would set any css property. This will be the line read by Mozilla browsers. The next line will be the underline (_) which will be read by IE 6.0+ which will overwrite the property for IE browsers but not for Mozilla browsers. While the dash (-) is only read by IE 6.0. So putting these together you can achieve the look you want across all browsers. Open this page in your other browsers to see this css file in action.
There are many other ways to achieve this action, for example with the exclamation point (!) and the !important attribute, but this example seems the easiest to remember for me.
Browsing with Firefox!
Browsing with IE6!
Browsing with IE7!
div.MyBody
{
background: red;
color: black;
}
div.FF
{
background: lime;
_background: red;
-background: red;
}
div.IE7
{
background: red;
_background: lime;
-background: red;
}
div.IE6
{
background: red;
_background: red;
-background: lime;
}