views:

489

answers:

1

I have been looking at a hack to solve a CSS problem I have. I haved used one to create a custom rule for Internet Explorer.

margin-top:45px;
*margin-top:0px;

Does this hack apply to all IE browsers? Does this hack appear in any versions of Firefox or Safari?

+3  A: 

This applies to IE7 and below. But be aware that this is not valid CSS, and it could break at any time. See here for a more comprehensive list of the various CSS hacks and which browsers they affect.

Although Internet Explorer 7 corrected its behavior when a property name is prefixed with an underscore or a hyphen, other non-alphanumeric character prefixes are treated as they were in IE6. Therefore, if you add a non-alphanumeric character such as an asterisk (*) immediately before a property name, the property will be applied in IE and not in other browsers. Unlike with the hyphen and underscore method, the CSS specification makes no reservations for the asterisk as a prefix, so use of this hack could result in unexpected behavior as the CSS specifications evolve.

I'd strongly recommend reconsidering whether you really need this hack, and if there isn't a better way to do what you want.

John Feminella
Well, I'd prefere not to use a conditional comment to include another style sheet, that means another HTTP request for IE users.
Sam152
That's a bit of a false dilemma -- you don't necessarily have to choose between (a) conditional stylesheet and (b) CSS hacks. There are ways to write CSS so that they look the same in IE and other browsers, although I concede that's a little harder.
John Feminella
The particular situation im in is a bit of a pickel. Something to do with the way IE handles nested UL's and floats.
Sam152
Perhaps you should ask a new question for that, then! (And accept this one as closed if it meets your definition... ;) )
John Feminella