Are there W3C-compatible hacks for IE6 and 7?

2019-07-10 05:17发布

问题:

Are there valid hacks in IE6 and 7 for W3C compatibility?

I believe there are W3C incompatibilities when using hacks. For example, using the following CSS code (as suggested under option 2 in this article: http://webdesignerwall.com/tutorials/css-specific-for-internet-explorer?cp=1):

.box {
    height:200px;
    _height:200px;
}

gave me the following error in the W3C CSS validator:

Property _height doesn't exist : 200px 200px

If I'm wrong please advise.

Thank you.

回答1:

This alternative hack should do it:

/* Both of the following will be used by IE only. */
* html .box{height:200px;} /* IE6 only */
*+html .box{height:200px;} /* IE7 only */


回答2:

Options 1 and 3 in that article — i.e. HTML conditional comments — are the way to go. They don’t trip up the HTML validator, and they’re explicit — they say “use this code for this version of IE”.

You can use them to apply different stylesheets that only fix Internet Explorer bugs. This keeps your IE bug workarounds separate, so that when, for example, the IE6 countdown reaches zero, you can remove your IE 6-specific CSS without affecting anything else.