IE兼容性

2020-04-22  本文已影响0人  杨戬Yj

其他浏览器会将其作为注释而忽略这些语句,他们是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]-->
<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 ]--> 
<!--[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]-->
<script>
    document.addEventListener('DOMContentLoaded', function () {
        objectFit.polyfill({
            selector: '.empowerment img',
            fittype: 'cover'
        });
    });
</script>

官方使用教程 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);
}
RGBA

(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下的效果


border-image

IETester下的效果


border-image

(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

background-size
(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);
}
背景渐变
  1. 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)。

  2. 相当路径的问题
    IE浏览器的behavior 属性是相对于HTML文档而言的,与CSS其他的属性不一样,不是相对于CSS文档而言的。这使得使用pie.htc文件不怎么方面。如果绝对路径于根目录,则CSS文件不方便移动;如果相对路径与HTML文档,则pie.htc文件在不同HTML页面见的重用性大大降低。同时,诸如border-image后面的URL属性路径也不好处理。

  3. 缩写的问题
    使用PIE实现IE下的CSS3渲染(其他方法也是一样),只能使用缩写的形式,例如圆角效果,我们可以设置border-top-left-radius表示左上圆角,但是PIE确实不支持这种写法的,只能是老老实实的缩写。

https://blog.csdn.net/clh604/article/details/11475783

上一篇 下一篇

猜你喜欢

热点阅读