bootstrap相容IE各版本的瀏覽器的問題__JavaScript

來源:互聯網
上載者:User

Bootstrap的目標是在最新的案頭和行動瀏覽器上有最佳的表現,也就是說,在較老舊的瀏覽器上可能會導致某些組件表現出的樣式有些不同,但是功能是完整的。

bootstrap3支援的瀏覽器:

 

Chrome (Mac、Windows、iOS和Android)

Safari (只支援Mac和iOS版,Windows版已經基本死掉了)

Firefox (Mac、Windows)

Internet Explorer

Opera (Mac、Windows)

Bootstrap在Chromium、Linux版Chrome、Linux版Firefox和Internet Explorer 7上的表現也是很不錯的,只是官方並不提供支援。

Internet Explorer 8 和 9的很多CSS3屬性和HTML5元素,例如圓角矩形和投影,不支援。

Internet Explorer 6 幾乎不支援,nav,  pagination 等在ie6上表現都特別差。

使用bootstrap2的bsie外掛程式 http://www.bootcss.com/p/bsie/ ,提取外掛程式裡的 bootstrap-ie6.css 和ie.css,在頁面的head裡bootstrap.css之下加入如下代碼:

<!--[if lte IE 6]>

<link rel="stylesheet" type="text/css" href="/css/bootstrap-ie6.css?1">

<![endif]-->

<!--[if lte IE 7]>

<link rel="stylesheet" type="text/css" href="/css/ie.css">

<![endif]-->

禁用響應式布局:

 

<link href="/css/non-responsive.css" rel="stylesheet" media="screen">

 

html裡的css代碼:

 

<style type="text/css">

body {

    padding-top: 60px;

    padding-bottom: 40px;

}

/* 禁用響應式布局:重新設定container的寬度。如果沒有後面三行的代碼,在IE6環境下navbar-top會顯示為940px寬度 */

.container,

.navbar-static-top .container,

.navbar-fixed-top .container,

.navbar-fixed-bottom .container {

    width:1140px;

}

</style>

 

開啟 bootstrap-ie6.css檔案,將檔案裡的pager替換為pagination,用於支援bootstrap3的分頁組件。並在底部加入如下代碼,代碼作用請看注釋:

 

/* 柵欄系統,溢出的問題 */

.col-xs-1 {

  width: 5.7%;

}

.col-xs-2 {

  width: 13.96%;

}

.col-xs-3 {

  width: 22.2%;

}

.col-xs-4 {

  width: 30.5%;

}

.col-xs-5 {

  width: 38.8%;

}

.col-xs-6 {

  width: 47%;

}

.col-xs-7 {

  width: 55.2%;

}

.col-xs-8 {

  width: 63.5%;

}

.col-xs-9 {

  width: 72%;

}

.col-xs-10 {

  width: 80%;

}

.col-xs-11 {

  width: 88.3%;

}

.col-xs-12 {

  width: 100%;

}

 

/* 修複ie6下分頁組件css解析失敗的問題 */

.pagination .active a,

.pagination .active span {

  z-index: 2;

  color: #ffffff;

  cursor: default;

  background-color: #428bca;

  border-color: #428bca;

}

 

/* 修複ie6下input樣式被重寫的問題*/

.form-control{

  display: block;

  width: 100%;

  height: 34px;

  padding: 6px 12px;

  font-size: 14px;

  line-height: 1.428571429;

  color: #555555;

  vertical-align: middle;

  background-color: #ffffff;

  border: 1px solid #cccccc;

  border-radius: 4px;

}

在html頁body之上添加如下代碼:

 

<!--[if lte IE 6]>

<script type="text/javascript" src="/js/bootstrap-ie.js"></script>

<![endif]-->

<script type="text/javascript">

(function ($) {

  $(document).ready(function() {

    if ($.isFunction($.bootstrapIE6)) $.bootstrapIE6($(document));

  });

})(jQuery);

</script>

 

html整個頭部檔案如下:

 

<!DOCTYPE HTML>

<html>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<link href="/css/bootstrap.min.css" rel="stylesheet" media="screen">

<!-- Bootstrap theme -->

<link href="/css/bootstrap-theme.min.css" rel="stylesheet">

<!--[if lte IE 6]>

<link rel="stylesheet" type="text/css" href="/css/bootstrap-ie6.css?1">

<![endif]-->

<!--[if lte IE 7]>

<link rel="stylesheet" type="text/css" href="/css/ie.css">

<![endif]-->

<link href="/css/non-responsive.css" rel="stylesheet" media="screen">

<link href="/css/showLoading.css" rel="stylesheet" media="screen">

<script type="text/javascript" src="/js/jquery-1.10.2.min.js"></script>

<script type="text/javascript" src="/js/bootstrap.min.js"></script>

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->

<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->

<!--[if lt IE 9]>

  <script src="/js/html5shiv.js"></script>

  <script src="/js/respond.min.js"></script>

<![endif]-->

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.