开发者

how to validate IE 7/8 CSS hacks?

I've used the conditional comments technique for my IE6/7/8 CSS "hacks", so that the main CSS file (with the common/standard classes) validates correctly (isolating the IE "hacks" in separate CSS files).

Something like this:

<!--[if IE 7]>
<link href="css/layoutIE7.css" rel="stylesheet" type="text/css" />
<![endif]-->
开发者_Python百科

Now I've started using conditional comments to add a class to the <body> (please read this answer: CSS if statements... is it right? ) and then target the class that needs a "hack" in my main CSS file, this way I can have only one file.

The problem with this method is that because I have everything in one file, it means that in case I have something as "simple" as the CSS3 opacity property:

.mydiv {
    opacity:0.6;
}

The IE "counterpart" (i.e.: "hack") will have to be something like:

.mydiv {
    filter:alpha(opacity=60);
 }

Which doesn't validate correctly.

I know the method I was using before still had this problem, but since you could test the site in a non-IE environment, it always validated (because I made sure the main CSS was valid), now since I'm trying to have one single CSS it doesn't validate (for the reasons explained).

My question is how to add this "hacks" in a way that the validator considers it valid?

Hopefully the answer should be CSS only.


CSS validation is overrated. Honestly.

As long as your markup validates, your CSS is constructed well and the site works in all your target browsers then you've done your job. The falacy that CSS must validate is long dead.


I don't think this is possible. If a non-standard CSS property is present in the style sheet, it won't validate. Nothing one can do to change that.

I think you'll have to choose either valid CSS, or using multiple style sheets.


There is no way to validate CSS hacks. If you want your CSS to be valid, go back to the conditional comments solution you were using before. Regarding CSS validation, many Web Designer gurus such as Andy Clarke or Zeldman have repeatedly said CSS should be used as helpful tool, not as a rule. It does not add any practical value besides helping you correct syntax errors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜