IE怎么可能会为了CSS样式而改变

if IE这样的判断语句其实并非只适合引入相应的CSS或js,也可以用在HTML中引入相关的HTML内容,但是在实际应用的时候,大多的应用场合是用来引入相应的CSS或js的。我们在这篇文章里以引入相应的CSS为实例。

对于if IE判断语句本身,其结构是:

  1. <!--[if 条件]> 符合条件的结果<br> <![endif]-->  

然后是条件所需的几个保留字符:

!:非;

lt:其实就是<,小于号;

gt:其实就是>,大于号;

e:等于,必须跟在lt或gt之后使用,构成小于等于或者大于等于;

下面是if IE的判断语句的应用实例和释义,重点是几个

  1. <!--[if !IE]> 除IE外都可识别<br>  <!--<![endif]-->  
  2.   
  3. <!--[if IE]> 所有的IE可识别 <br> <![endif]-->  
  4.   
  5. <!--[if IE 8]> 仅IE8可识别 <br> <![endif]-->  
  6.   
  7. <!--[if lt IE 9]> IE9以下版本可识别 <br> <![endif]-->  
  8.   
  9. <!--[if gt IE 6]> IE6以上版本可识别<br> <![endif]-->  
  10.   
  11. <!--[if lte IE 8]> IE8及以下版本可识别 <br> <![endif]-->  
  12.   
  13. <!--[if gte IE 6]> IE6以及IE6以上版本可识别<br> <![endif]-->  
  14.   
  15. <!--[if (gt IE 6)&(lte IE 9)]> IE7/IE8/IE9版本可识别<br> <![endif]-->  
  16.   
  17. <!--[if (IE 7)|(IE 8)]> IE7或IE8版本可识别<br> <![endif]-->  

 

写在HTML的body测试:

  1. <!doctype html>  
  2. <html lang="zh_CN">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>'if IE' test Document by Suoling.net</title>  
  6. </head>  
  7. <body>  
  8. <!--[if !IE]> 除IE外都可识别<br>  <!--<![endif]-->  
  9.   
  10. <!--[if IE]> 所有的IE可识别 <br> <![endif]-->  
  11.   
  12. <!--[if IE 8]> 仅IE8可识别 <br> <![endif]-->  
  13.   
  14. <!--[if lt IE 9]> IE9以下版本可识别 <br> <![endif]-->  
  15.   
  16. <!--[if gt IE 6]> IE6以上版本可识别<br> <![endif]-->  
  17.   
  18. <!--[if lte IE 8]> IE8及以下版本可识别 <br> <![endif]-->  
  19.   
  20. <!--[if gte IE 6]> IE6以及IE6以上版本可识别<br> <![endif]-->  
  21.   
  22. <!--[if (gt IE 6)&(lte IE 9)]> IE7/IE8/IE9版本可识别<br> <![endif]-->  
  23.   
  24. <!--[if (IE 7)|(IE 8)]> IE7或IE8版本可识别<br> <![endif]-->  
  25.   
  26. </body>  
  27. </html>  

 

 

用IE8打开,会看到:

  1. 所有的IE可识别    
  2. 仅IE8可识别    
  3. IE9以下版本可识别    
  4. IE6以上版本可识别   
  5. IE8及以下版本可识别    
  6. IE6以及IE6以上版本可识别   
  7. IE7/IE8/IE9版本可识别   
  8. IE7或IE8版本可识别   

 

应用举例:

对于非IE的浏览器:

  1. <!--[if !IE]><!-->  
  2. <link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css" />  
  3. <!--<![endif]-->  

 

对于全部IE浏览器:

  1. <!--[if !IE]><!-->  
  2.  <link type="text/css" rel="stylesheet" href="/stylesheets/for-ie.css" />  
  3.     <!--<![endif]-->  

对于IE8浏览器:

  1. <!--[if !IE 8]><!-->  
  2.  <link type="text/css" rel="stylesheet" href="/stylesheets/for-ie8.css" />  
  3.     <!--<![endif]-->  

 

你可以根据自己的实际需求,用if IE引入自己的css或js了,当然,HTML内容也是可以的,比如,当IE浏览器版本过低的时候!

posted @ 2014-01-08 11:24  lanhe  阅读(237)  评论(0编辑  收藏  举报
数据中心