近期在使用bootstrap這個優秀的前端框架,這個框架很是強大,框架裏面有下拉菜單、按鈕組、按鈕下拉菜單、導航、導航條、麪包屑、分頁、排版、縮略圖、警告對話框、進度條、媒體對象等,bootstrap都已經預先定義好了,當咱們製做網頁上,只需直接調用裏面的css便可javascript
bootstrap是一個響應式的佈局,你能夠在寬屏電腦、普通電腦,平板電腦,手機上都獲得很是優秀的佈局體驗。這種響應式的佈局正是經過CSS3的媒體查詢(Media Query)功能實現的,根據不一樣的分辨率來匹配不一樣的樣式。IE8瀏覽器並不支持這一優秀的Css3特性,Bootstrap在開發文檔中寫了如何使用進行兼容IE8,若是想兼容IE6,IE7,能夠搜索bsie (bootstrap2)css
Bootstrap在IE8中確定不如Chrome、Firefox、IE11那麼完美,部分組件不保證徹底兼容,仍是要Hack的html
一、使用html5聲明前端
<!DOCTYPE html> 這裏不能夠有空格 <html>
注:寫成<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">是不可行的html5
二、加入meta標籤java
肯定顯示此網頁的IE版本jquery
<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 Framegit
三、引入bootstrap文件github
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet">
四、引入html5shiv.min.js和respond.min.jschrome
讓不(徹底)支持html5的瀏覽器「支持」html5標籤
<!--[if lt IE 9]> <script src="js/bootstrap/html5shiv.min.js"></script> <script src="js/bootstrap/respond.min.js"></script> <![endif]-->
五、添加1.X版本的Jquery庫
<script src="js/bootstrap/jquery-1.12.0.min.js"></script>
六、在IE8下測試,發現一個問題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版本,再引入
<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>
附註:
一、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裏的不等於判斷符相同
二、bootstrap3相關css、js
下載地址:http://pan.baidu.com/s/1getpDjt
jquery.placeholder.js文件的下載地址https://github.com/mathiasbynens/jquery-placeholder