Forum Moderators: not2easy
So, in case you still want to hide stuff from IE6, here's a new hack you can use. I haven't tested it in older IE versions, but I suppose it should work in those too.
<style type="text/css">
#mydiv {
color: blue;
drdoc: ";
drdoc: "";
color: red;
background: silver;
/*";/* IE */
font-weight: bold;
}
#nextdiv {
color: red;
}
body {
background: navy;
}
</style>Note: IE will continue parsing after /* IE */
The lines in bold are of course dummies. They could be called anything, preferably a property that doesn't exist. That way it won't cause errors in other browsers since they should ignore rules that aren't properly formed.
Here's another example:
<style type="text/css">
#mydiv {
color: blue;
drdoc: ";
color: red;
background: silver;
/*";/* IE */
font-weight: bold;
}
#nextdiv {
color: red;
}
body {
background: navy;
}
</style>Note: IE will continue parsing after /* IE */
NN6 will hide the next rule
NN6/Mozilla will parse everything correctly, except the rule immediately following the hack, which will be ignored.
These hacks don't cause any problems in other browsers, as far as I know. If you notice anything, please post on here.
NN4 will of course choke on the hacks, but it's easy to work around that by using the comment hack for NN4.
<style type="text/css">
#mydiv {
color: blue;/*/*/
drdoc: ";
drdoc: "";/* NN4 */
color: red;
background: silver;
/*";/* IE */
font-weight: bold;
}
#nextdiv {
color: red;
}
body {
background: navy;
}
</style>
Hiding color changes is hardly what you want to do, though. But there are always margin issues and other bizarre bugs you might want to work around. I just used colors for simplicity.
Disclaimer: I do not recommend using hacks of any kind. I believe there are always other workarounds, especially if the hack will cause my HTML or CSS not to validate. But, for those of you that rely on hacks like these - you're welcome!
It does, however, seem like a complex work around for something that can be accomplished using other, simpler tricks such as child and/or attribute selctors, which will hide CSS from IE6.
Check out the following URL for details.
http://w3development.de/css/hide_css_from_browsers/summary/
[edited by: Nick_W at 1:20 pm (utc) on Mar. 2, 2003]
[edit reason] Only De-Linked ;-) [/edit]