html引用Bootstrap 針對IE低版本瀏覽器的兼容寫法

CSS3屬性border-radius/box-shadow/transform/transition/placeholder這些屬性在IE8以及IE9中會有兼容問題

<!DOCTYPE html>
<html lang="en">
<head>
    <!-- 編碼格式 -->
    <meta charset="UTF-8">
    <title></title>
    <!-- 作者 -->
    <meta name="author" content="author">
    <!-- 網頁描述 -->
    <meta name="description" content="hello">
    <!-- 關鍵字使用","分隔 -->
    <meta name="keywords" content="a,b,c">
    <!-- 禁止瀏覽器從本地機的緩存中調閱頁面內容 -->
    <meta http-equiv="Pragma" content="no-cache">
    <!-- 用來防止別人在框架裏調用你的頁面 -->
    <meta http-equiv="Window-target" content="_top">
    <!-- content的參數有all,none,index,noindex,follow,nofollow,默認是all -->
    <meta name="robots" content="none">
    <!-- 收藏圖標 -->
    <link rel="Shortcut Icon" href="favicon.ico">
    <!-- 網頁不會被緩存 -->
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
    <!-- 解決部分兼容性問題,如果安裝了GCF,則使用GCF來渲染頁面,如果未安裝GCF,則使用最高版本的IE內核進行渲染。 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <!-- 頁面按原比例顯示 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="plugin/bootstrap-3.3.0/css/bootstrap.min.css">
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.js"></script>
    <![endif]-->
</head>
<body>
    <script src="plugin/jquery/jquery-1.11.2.min.js"></script>
</body>
</html>

注: 其中 html5shiv.min.js 文件是讓不(完全)支持html5的瀏覽器支持 html5 標籤;respond.js 文件是讓IE8實現對媒體查詢(media query)的支持。

但是,在IE8瀏覽器中打開頁面發現,兼容性問題並沒有得到解決(坑、坑、坑)。通過查閱相關資料,筆者總結幾點注意事項(效果實現的關鍵):

  • 本地調試需要Web Server(如IIS、Apache,Nginx),單純地本地打開文件不能看到兼容效果;
  • 如果你發現已經引用了 respond.js 和 Bootstrap,仍無效果,請查看你的Bootstrap是否使用了CDN文件;
  • Bootstrap3 需要Html5文檔聲明;
  • Jquery 版本需要在2.0以下。

https://www.jianshu.com/p/bc8ae9bfa1ef

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章