<!--[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]-->

What are these useful for? What is the best and the most suitable codes as above should be in a web page?

有帮助吗?

解决方案

Those are conditional comments.

The <!--[if IE.. comments are generally used for including some custom code in the HTML file only if the browser is some version of IE.

Specifically the code you posted detects multiple versions of IE including a Windows Phone 7 browser and defines CSS classes on the html root element accordingly.

This allows you to write CSS targetd specifically for that browser like this:

.iem7 .my .selector {
    /* this rule will apply only if the browser is ie on windows phone 7 */
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top