为样式表创建有效的条件注释,而不会出现"伪造注释"验证器错误

Hii*_*ran 5 html validation conditional-comments

我的头标记中有以下内容:

<link rel="stylesheet" href="Scripts/styleMain.css" media="all" type="text/css" />
<![if gte IE 9]><!-->
<link rel="stylesheet" href="Scripts/styleMob.css" media="screen and (max-width:500px)" type="text/css" />
<link rel="stylesheet" href="Scripts/styleDes.css" media="screen and (min-width:501px)" type="text/css" />
<!--<![endif]-->
<!--[if lt IE 9]>
<link rel="stylesheet" href="styleDes.css" type="text/css" />
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

问题是,第二行被认为是虚假评论,而同一行上的第二个标记被认为是评论的过早结束.

在同一行上添加额外的标签,并在第一个endif上给我两个假的评论错误.

有什么方法可以让我的样式表有条件,并让他们验证?或者我注定要在我的OCD编码中使用无效的代码?

Bol*_*ock 7

你的第二行在错误的地方有开头的评论分隔符:

<!--[if gte IE 9]><!-->
Run Code Online (Sandbox Code Playgroud)

请注意,此处的语法突出显示它现在正确地突出显示为注释.

下面将正确突出为好,因为标记的其余部分<!-->是现在被看作是<!其次-->的,而不是<!--之后>,因为它会一直在你无效的标记:

<link rel="stylesheet" href="Scripts/styleMain.css" media="all" type="text/css" />
<!--[if gte IE 9]><!-->
<link rel="stylesheet" href="Scripts/styleMob.css" media="screen and (max-width:500px)" type="text/css" />
<link rel="stylesheet" href="Scripts/styleDes.css" media="screen and (min-width:501px)" type="text/css" />
<!--<![endif]-->
<!--[if lt IE 9]>
<link rel="stylesheet" href="styleDes.css" type="text/css" />
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

代码中没有突出显示为注释的位将是IE9及其他浏览器以及其他浏览器将如何看到您的标记.较旧的IE只会看到您的第一个和最后一个<link>元素.