HTML條件注釋用法詮釋

2018-4-24    seo達(dá)人

如果您想訂閱本博客內(nèi)容,每天自動(dòng)發(fā)到您的郵箱中, 請(qǐng)點(diǎn)這里

HTML條件注釋用法詮釋

注釋內(nèi)容以樣式為例,如下:

1、支持所有IE瀏覽器

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

2、支持非IE瀏覽器

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

上面是除了IE瀏覽器外所有瀏覽器都識(shí)別這個(gè)樣式,另外CSS-TRICKS《How To Create an IE-Only Stylesheet》一文中提供了另一種寫法:

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

3、僅僅支持IE10

<!--[if IE 10]>
<link rel="stylesheet" type="text/css" href="ie10.css">
<![endif]-->
    
  • 1
  • 2
  • 3

4、支持IE10以下版本(IE9以及IE9以下版本)

這種方法是樣式表使用在低于IE10的瀏覽器,換句話說(shuō)除了IE10以外的所有IE版本都將被支持。

<!--[if lt IE 10]>
<link rel="stylesheet" type="text/css" href="ie9-and-down.css">
<![endif]-->
    
  • 1
  • 2
  • 3

也可以寫成

<!--[if lte IE 9]>
<link rel="stylesheet" type="text/css" href="ie9-and-down.css">
<![endif]-->
    
  • 1
  • 2
  • 3

前面我們也說(shuō)過(guò)了lt和lte的區(qū)別,lt表示小于版本號(hào),不包括條件版本號(hào)本身;而lte是小于或等于版本號(hào),包括了版本號(hào)自身。

上面這幾種方法,使用的是低于(lt)和低于或等于(lte)的方法來(lái)判斷,我們也可以使用大于gt和大于或等于gte達(dá)到上面的效果:

5、高于IE9的版本(IE10以及IE10以上版本)

<!--[if gt IE 9]>
<link rel="stylesheet" type="text/css" href="ie10-and-up.css">
<![endif]-->
    
  • 1
  • 2
  • 3

<!--[if gte IE 10]>
<link rel="stylesheet" type="text/css" href="ie10-and-up.css">
<![endif]-->
    
  • 1
  • 2
  • 3

6、指定多種IE版本

<!--[if (IE 6)|(IE 7)|(IE 8)]>
<link rel="stylesheet" type="text/css" href="ie6-7-8.css">
<![endif]-->
    
  • 1
  • 2
  • 3

參考: 
https://www.cnblogs.com/hushufang/p/3708704.html

藍(lán)藍(lán)設(shè)計(jì)sillybuy.com )是一家專注而深入的界面設(shè)計(jì)公司,為期望卓越的國(guó)內(nèi)外企業(yè)提供卓越的UI界面設(shè)計(jì)、BS界面設(shè)計(jì) 、 cs界面設(shè)計(jì) 、 ipad界面設(shè)計(jì) 、 包裝設(shè)計(jì) 、 圖標(biāo)定制 、 用戶體驗(yàn) 、交互設(shè)計(jì)、 網(wǎng)站建設(shè) 、平面設(shè)計(jì)服務(wù)

分享本文至:

日歷

鏈接

個(gè)人資料

存檔