bootstrap3 兼容IE8瀏覽器!IE8瀏覽器并不支持這一優(yōu)秀的Css3特性,Bootstrap在開發(fā)文檔中寫了如何使用進行兼容IE8,感興趣的朋友可以參考一下
近期在使用bootstrap這個優(yōu)秀的前端框架,這個框架非常強大,框架里面有下拉菜單、按鈕組、按鈕下拉菜單、導航、導航條、面包屑、分頁、排版、縮略圖、警告對話框、進度條、媒體對象等,bootstrap都已經預先定義好了,當我們制作網頁上,只需直接調用里面的css即可
bootstrap是一個響應式的布局,你可以在寬屏電腦、普通電腦,平板電腦,手機上都得到非常優(yōu)秀的布局體驗。這種響應式的布局正是通過CSS3的媒體查詢(Media Query)功能實現的,根據不同的分辨率來匹配不同的樣式。IE8瀏覽器并不支持這一優(yōu)秀的Css3特性,Bootstrap在開發(fā)文檔中寫了如何使用進行兼容IE8,如果想兼容IE6,IE7,可以搜索bsie (bootstrap2)
Bootstrap在IE8中肯定不如Chrome、Firefox、IE11那么完美,部分組件不保證完全兼容,還是要Hack的
1、使用html5聲明
<!DOCTYPE html>
這里不可以有空格
<html>
注:寫成<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">是不可行的
2、加入meta標簽
確定顯示此網頁的IE版本
<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
注:bootstrap不支持IE兼容模式,為了讓IE瀏覽器運行最新的渲染模式,將添加以上標簽在頁面中,IE=edge表示強制使用IE最新內核,chrome=1表示如果安裝了針對IE6/7/8等版本的瀏覽器插件Google Chrome Frame
3、引入bootstrap文件
代碼如下:
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet">
4、引入html5shiv.min.js和respond.min.js
讓不(完全)支持html5的瀏覽器“支持”html5標簽
<!--[if lt IE 9]>
<script src="js/bootstrap/html5shiv.min.js"></script>
<script src="js/bootstrap/respond.min.js"></script>
<![endif]-->
5、添加1.X版本的Jquery庫
代碼如下:
<script src="js/bootstrap/jquery-1.12.0.min.js"></script>
6、在IE8下測試,發(fā)現一個問題placeholder不被支持,下面是解決IE支持placeholder的方法,本文引用的jquery是1.12.0測試通過,先引用jquery
<script type="text/javascript" src="js/bootstrap/jquery-1.12.0.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
也可以用其他的jquery版本,再引入
[code]<script type="text/javascript" src="js/bootstrap/jquery.placeholder.js"></script>
然后在文件中加入一下代碼
<script type="text/javascript">
$(function () {
$('input, textarea').placeholder();
});
</script>
代碼總結如下:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
<meta name="author" content="zhy" />
<title>ie8</title>
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css">
<!--[if lte IE 9]>
<script src=js/bootstrap/respond.min.js"></script>
<script src=js/bootstrap/html5shiv.min.js"></script>
<![endif]-->
<script src="js/bootstrap/jquery-1.12.0.min.js"></script>
<script src="js/bootstrap/bootstrap.min.js"></script>
</head>
<body>
</body>
</html>
附注:
1、IE下判斷IE版本的語句
<!--[if lte IE 6]>
<![endif]-->
IE6及其以下版本可見
<!--[if lte IE 7]>
<![endif]-->
IE7及其以下版本可見
<!--[if IE 6]>
<![endif]-->
只有IE6版本可見
<![if !IE]>
<![endif]>
除了IE以外的版本
<!--[if lt IE 8]>
<![endif]-->
IE8以下的版本可見
<!--[if gte IE 7]>
<![endif]-->
IE7及大于IE7的版本可見
lte:就是Less than or equal to的簡寫,也就是小于或等于的意思。
lt :就是Less than的簡寫,也就是小于的意思。
gte:就是Greater than or equal to的簡寫,也就是大于或等于的意思。
gt :就是Greater than的簡寫,也就是大于的意思。
! : 就是不等于的意思,跟javascript里的不等于判斷符相同
以上就是本文的全部內容,希望對大家的學習有所幫助。