其他浏览器会将其作为注释而忽略这些语句,他们是IE专门提供的一种语法
<!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]-->
<!--[if IE]> 所有的IE可识别 <![endif]-->
<!--[if IE 6]> 仅IE6可识别 <![endif]-->
<!--[if lt IE 6]> IE6以及IE6以下版本可识别 <![endif]-->
<!--[if gte IE 6]> IE6以及IE6以上版本可识别 <![endif]-->
<!--[if IE 7]> 仅IE7可识别 <![endif]-->
<!--[if lt IE 7]> IE7以及IE7以下版本可识别 <![endif]-->
<!--[if gte IE 7]> IE7以及IE7以上版本可识别 <![endif]-->
<!--[if IE 8]> 仅IE8可识别 <![endif]-->
<!--[if IE 9]> 仅IE9可识别 <![endif]-->
- bootstrap4对于IE的兼容:
<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
.row:after{content:'';display:table;clear:both;}
IE=edge表示强制使用IE最新内核,chrome=1表示如果安装了针对IE6/7/8等版本的浏览器插件Google Chrome Frame(可以让用户的浏览器外观依然是IE的菜单和界面,但用户在浏览网页时,实际上使用的是Chrome浏览器内核),那么就用Chrome内核来渲染
<!--[if IE 9]>
<link href ="https://cdn.jsdelivr.net/gh/coliff/bootstrap-ie8/css/bootstrap-ie9.min.css" rel ="stylesheet">
<!-- <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script> -->
<!-- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script> -->
<script src ="https://cdn.jsdelivr.net/gh/coliff/bootstrap-ie8/js/bootstrap-ie9.min.js"></script>
<![endif ]-->
- boostrap3对于IE的兼容
<!--[if lt IE 9]>
<script src="http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min.js"></script>
<script src="http://apps.bdimg.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
-
object-fit 兼容IE
引入云盘js文件polyfill.object-fit.min.css /// polyfill.object-fit.min.js;
<script>
document.addEventListener('DOMContentLoaded', function () {
objectFit.polyfill({
selector: '.empowerment img',
fittype: 'cover'
});
});
</script>
-
IE6/7/8/9兼容CSS样式
1 使用 PIE.htc
behavior:url(PIE.htc);
pie.htc是一个可以解决IE6/7/8无法支持CSS3属性的文件,其利用VML绘制相关的效果。要注意的是它并不能实现所有CSS3效果,其兼容的属性有:box-radius
,线性渐变(linear-gradient
),rgba
,box-shadow
,border-image
。
使用behavior:url(pie.htc)引入pie.htc即可完成相关效果了。以下实例均使用IETester进行测试,主要测试IE6/7/8的效果
官方使用教程 http://css3pie.com/documentation/supported-css3-features/
(1) 圆角(border-radius)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.demo{
height: 100px ;
width:200px;
border:1px solid #00FFFF;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
behavior: url(static_resources/PIE.htc);
}
</style>
<body>
<div class="demo"></div>
</body>
</html>

(2) 盒阴影(box-shadow)
.demo{
height: 100px ;
width:200px;
background: #00FFFF;
-webkit-box-shadow: 10px 10px 5px #888888;
-moz-box-shadow: 10px 10px 5px #888888;
box-shadow: 10px 10px 5px #888888;
behavior: url(static_resources/PIE.htc);
}

(3) RGBA
.demo{
height: 100px ;
width:200px;
background: rgba(0,0,0,0.5);
-pie-background:rgba(0,0,0,0.5);
behavior: url(static_resources/PIE.htc);
}

(4) border-image
.demo{
height: 100px ;
width:200px;
border:15px solid transparent;
-webkit-border-image: url(img/border.png) 30 30 round;
-moz-border-image: url(img/border.png) 30 30 round;
-o-border-image: url(img/border.png) 30 30 round;
border-image: url(img/border.png) 30 30 round;
behavior: url(static_resources/PIE.htc);
}
IE6/7/8只会以stretch的形式进行填充,即使border-image-repeat属性是repeat和round
Chrome下的效果

IETester下的效果

(5) background-size
.demo{
height: 100px ;
width:200px;
background-image: url("img/1.jpg");
background-size: cover;
behavior: url(static_resources/backgroundsize.min.htc);
}
针对兼容
background-size
使用了backgroundsize.htc
,支持IE7/8,无法支持IE6

(6) Gradient背景渐变(支持线性渐变)
.demo{
height: 100px ;
width:200px;
background:linear-gradient(90deg,#00FFFF,#0000FF);
-pie-background:linear-gradient(0,#00FFFF,#0000FF);
behavior: url(static_resources/PIE.htc);
}

-
下载地址
pie.htc下载地址: http://css3pie.com/download/ -
PIE方法无效的解决方法:
-
z-index相关问题
IE下这些CSS3效果实现是借助于VML,由VML绘制圆角或是投影效果的容器元素,然后这个容器元素作为目标元素的后兄弟节点插入,如果目标元素position:absolute 或是 position:relative,则这个css3-container元素将会设置与之一样的z-index值,在DOM tree中,同级的元素总是后面的覆盖前面的,所以这样就实现了覆盖,又避免了可能有其他元素正好插入其中。所以,问题来了,如果目前元素的position属性为static,也就是默认属性,则z-index属性是没有用的,无覆盖可言,所以此时IE浏览器下CSS3的渲染是不会成功的。要解决也很简单,设置目标元素position:relative或是设置祖先元素position:relative并赋予一个z-index值(不可为-1)。
-
相当路径的问题
IE浏览器的behavior 属性是相对于HTML文档而言的,与CSS其他的属性不一样,不是相对于CSS文档而言的。这使得使用pie.htc文件不怎么方面。如果绝对路径于根目录,则CSS文件不方便移动;如果相对路径与HTML文档,则pie.htc文件在不同HTML页面见的重用性大大降低。同时,诸如border-image后面的URL属性路径也不好处理。 -
缩写的问题
使用PIE实现IE下的CSS3渲染(其他方法也是一样),只能使用缩写的形式,例如圆角效果,我们可以设置border-top-left-radius表示左上圆角,但是PIE确实不支持这种写法的,只能是老老实实的缩写。
网友评论