Valid conditional comments to target non-IE browse

2019-02-21 00:08发布

How do you use conditional comments to target

  1. Internet Explorer only

  2. Certain IE versions

  3. Certain IE versions and all other browsers

  4. No IE, just other browsers

in a way that validates? (validator.w3.org/)

1条回答
我想做一个坏孩纸
2楼-- · 2019-02-21 00:35

I tested these and they're valid HTML.

IMPORTANT: Only IE 5 through 9 support conditional comments.

<!-- 1. IE 5-9 only: -->

<!--<![if IE]>
    <link rel="stylesheet" type="text/css" href="ie-5-through-9.css">
<![endif]>-->


<!-- 2. Some IE versions -->

<!--<![if gte IE 8]>
    <link rel="stylesheet" type="text/css" href="ie-8-and-9.css">
<![endif]>-->


<!-- 3. Some IE versions, plus all non-IE browsers -->

<!--[if gte IE 8]>-->
    <link rel="stylesheet" type="text/css" href="ie-gte8-and-non-ie.css">
<!--<![endif]-->


<!-- 4. All browsers except IE 5-9 -->

<!--[if !IE]>-->
    <link rel="stylesheet" type="text/css" href="modern-ie-and-non-ie.css">
<!--<![endif]-->
查看更多
登录 后发表回答