如果以下代码有用,该怎么办?

时间:2013-11-11 04:58:03

标签: html internet-explorer meta-tags

<!--[if IEMobile 7 ]> 
<html lang="en-US"class="no-js iem7"> 
<![endif]-->

<!--[if lt IE 7 ]> 
<html lang="en-US" class="no-js ie6 oldie"> 
<![endif]-->

<!--[if IE 7 ]>    
<html lang="en-US" class="no-js ie7 oldie"> 
<![endif]-->

<!--[if IE 8 ]>    
<html lang="en-US" class="no-js ie8 oldie"> 
<![endif]-->

<!--[if (gte IE 9)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!-->
<html lang="en-US" class="no-js">
<!--<![endif]-->

这些有用的是什么?如上所述的最佳和最合适的代码应该在网页中?

1 个答案:

答案 0 :(得分:2)

那些是conditional comments

<!--[if IE..评论通常用于在HTML文件中包含一些自定义代码,仅当浏览器是某个版本的IE时才会这样。

具体而言,您发布的代码会检测IE including a Windows Phone 7 browser的多个版本,并相应地在html根元素上定义CSS类。

这允许您像这样编写专门针对该浏览器的CSS:

.iem7 .my .selector {
    /* this rule will apply only if the browser is ie on windows phone 7 */
}