bootstrap3 兼容IE8浏览器!

作者:缘天 时间:2023-07-02 05:18:58 

      近期在使用bootstrap这个优秀的前端框架,这个框架非常强大,框架里面有下拉菜单、按钮组、按钮下拉菜单、导航、导航条、面包屑、分页、排版、缩略图、警告对话框、进度条、媒体对象等,bootstrap都已经预先定义好了,当我们制作网页上,只需直接调用里面的css即可

bootstrap是一个响应式的布局,你可以在宽屏电脑、普通电脑,平板电脑,手机上都得到非常优秀的布局体验。这种响应式的布局正是通过CSS3的媒体查询(Media Query)功能实现的,根据不同的分辨率来匹配不同的样式。IE8浏览器并不支持这一优秀的Css3特性,Bootstrap在开发文档中写了如何使用进行兼容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下测试,发现一个问题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里的不等于判断符相同

如果大家还想深入学习,可以点击这里进行学习,再为大家附3个精彩的专题:

Bootstrap学习教程

Bootstrap实战教程

Bootstrap插件使用教程

标签:bootstrap3,兼容,IE8
0
投稿

猜你喜欢

  • MySQL分区表管理命令汇总

    2024-01-25 21:55:38
  • python各类经纬度转换的实例代码

    2023-12-24 12:19:58
  • Python中输出ASCII大文字、艺术字、字符字小技巧

    2021-03-03 00:06:49
  • python3 wechatpy微信支付的项目实践

    2023-08-29 14:13:36
  • Yii2 rbac权限控制之菜单menu实例教程

    2023-11-14 10:41:19
  • Go语言开发kube-scheduler整体架构深度剖析

    2024-04-28 09:17:20
  • python3+pyqt5+itchat微信定时发送消息的方法

    2022-02-28 04:31:49
  • python 中[0]*2与0*2的区别说明

    2021-11-01 07:46:17
  • Python实现脚本转换为命令行程序

    2022-02-28 10:48:30
  • python2 与 python3 实现共存的方法

    2023-06-13 23:56:29
  • 使用Matplotlib 绘制精美的数学图形例子

    2022-11-25 11:03:04
  • Python PSO算法处理TSP问题详解

    2022-12-02 02:39:24
  • 10分钟学会Google Map API (二)

    2009-06-07 18:14:00
  • 用Python写一个模拟qq聊天小程序的代码实例

    2022-04-01 10:01:42
  • node.js+express+mySQL+ejs+bootstrop实现网站登录注册功能

    2023-07-15 17:55:01
  • 如何让IIS支持wap,让ASP生成wml

    2008-05-18 13:42:00
  • django 扩展user用户字段inlines方式

    2022-02-28 00:50:14
  • 不用加载Include文件也能生成选择列表吗?

    2009-10-29 12:30:00
  • SQL 研究 相似的数据类型

    2024-01-15 11:20:44
  • Jupyter notebook如何修改平台字体

    2022-03-21 13:37:59
  • asp之家 网络编程 m.aspxhome.com