By Martin / (X)HTML & CSS / Tuesday August 5th, 2008 / No comments
Normally, I try not to use hacks, because they are... hacks, but there are sometimes irritating problems in IE that just won't go away, like the overflow:visible bug in IE 6.
So, we have to resort to something that will allow a CSS selector to be read only in IE 6 and below.
Enter the star (*) hack. It is cool, primarily because it is valid, but also because it is more logical than some of its weirder contemporaries.
In IE 6 and its microsoft predecessors, there is a strange "element" that surrounds your html node - the "<*>" element. This doesn't occur in other browsers, so to use the star hack all you have to do is place the asterix character followed by the html tag, and then your normal selectors. For example:
.myclass {
/* these properties will be parsed by all browsers */
}
* html .myclass {
/* these properties will only be read in IE lte 6! */
}
Because the * is a valid CSS selector (but meaning "all children", not as a tag), this CSS code will still validate perfectly. And it works!
∎
I hope you enjoyed reading this article. If you wish, you may view some of the other recent or popular things I have written, or subscribe to receive RSS updates. You can also add a comment, or share this article on Twitter or Facebook, below.
Website copyright © Aspektas 2009 - 2010 Valid XHTML 1.0 Strict and CSS 2.1