Home  >  Article  >  Web Front-end  >  A CSS Hack for IE7_Experience Exchange

A CSS Hack for IE7_Experience Exchange

WBOY
WBOYOriginal
2016-05-16 12:09:261091browse

IE7 has fixed many bugs and added support for some selectors, so now hacks for hiding or showing IE such as *html {} and html>body {} will not work in IE7. Although CSS Hack is not recommended and conditional comments are a foolproof filter, conditional comments can only appear in HTML, so CSS Hack still has its place. Nanobot discovered some CSS Hacks for IE7, specifically:

>body
html*
*+html

Of these three writing methods, the first two are illegal CSS writing methods and are ignored in standard-compliant browsers, but IE7 does not think so. For >body, it will replace the missing selector with the global selector *, that is, it will be processed into *>body, and this phenomenon also exists not only for the > selector, but also for the + and ~ selectors. For html*, since there is no space between html and *, it is also a CSS syntax error, but IE7 will not ignore it, but mistakenly believes that there is a space here. For the third type *+html, IE7 believes that the DTD declaration in front of html is also an element, so html will be selected. Among these three methods, only this method is legal CSS writing, which means it can pass the validator. Verification is therefore also a hack usage recommended by the author.

Finally the author gave the best way:

IE 6 and below
Use * html {} to select the html element.
IE 7 and below
Use *+html, * html {} to select the html element.
IE 7 only
Use **+html {} to select the html element.
IE 7 and modern browsers only
Use html>body {} to select the body element.
Modern browsers only (not IE 7)
Use html>/**/body {} to select the body element.

For specific information, please refer to the original text: Easy CSS hacks for IE7

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn