Jquery中文网 www.jquerycn.cn
Jquery中文网 >  CSS教程  >  经典实例  >  正文 css中filter滤镜,ie9 hack写法::root 选择器妙用

css中filter滤镜,ie9 hack写法::root 选择器妙用

发布时间:2020-05-09   编辑:www.jquerycn.cn
jquery中文网为您提供css中filter滤镜,ie9 hack写法::root 选择器妙用等资源,欢迎您收藏本站,我们将为您提供最新的css中filter滤镜,ie9 hack写法::root 选择器妙用资源
下面来看一个css中filter滤镜,ie9 hack写法::root 选择器妙用例子了,希望大家可以通过这个例子理深入的理解filter滤镜的用法哦。

需求: 实现一个层旋转270deg,ie系列浏览器全兼容

源码:

 代码如下 复制代码

<!--[if lte IE 8]>
 <style>
 #demo{filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3);}
 </style>
<![endif]-->
<style>
 #demo{
  width: 300px;height: 200px;background-color: #FF80C0;margin: 200px;
  -moz-transform:translate(-226px,226px) rotate(270deg);
  -webkit-transform:translate(-226px,226px) rotate(270deg);
  -ms-transform:translate(-226px,226px) rotate(270deg);
  -o-transform:translate(-226px,226px) rotate(270deg);
 }
</style>
<div id="demo">
 做个DEMO测试下
</div>


问题:

赞助商链接
ie9下旋转角度不正确!

问题所在:

ie9下会重复应用filter和 -ms-transform,会导致旋转角度不正确

解决方法:

方法1:

取消ie9下的滤镜css:
:root #demo{filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=0);}

这里用到了CSS3 :root 选择器:所有主流浏览器均支持 :root 选择器,除了 IE8 及更早的版本,而滤镜filterk只有ie9以及更低的ie版本才支持,ie10开始已废弃不支持filter,这样刚好可利用:root来实现针对ie9的hack!!
装了ie10或更高版本的ie,可用ietester新建ie9模式标签查看上面代码运行效果。
(注意:装了ie10或更高版本的ie,即使将文档模式调成ie9,会发现上面 的代码也显示正确,合理的解释是:ie10开始已废弃不支持filter,即使文档模式调成ie9,filter也不会生效!另外提一下 css 9 写法是针对ie所有版本的hack写法,网上说的只是针对ie6~8的hack说法是错误的!)

方法2:

用ie独有条件注释,把filter样式抽出来放到注释里面去,鉴于条件注释只能写入到页面上,所以还是推荐方法1去解决”ie9下会重复应用filter和 -ms-transform,会导致旋转角度不正确“这个问题

当然,还要放出方法2的源码:

 代码如下 复制代码

<!--[if lte IE 8]>
<style>
#demo{filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3);}
</style>
<![endif]-->
<style>
#demo{
width: 300px;height: 200px;background-color: #FF80C0;margin: 200px;
-moz-transform:translate(-226px,226px) rotate(270deg);
-webkit-transform:translate(-226px,226px) rotate(270deg);
-ms-transform:translate(-226px,226px) rotate(270deg);
-o-transform:translate(-226px,226px) rotate(270deg);
}
</style>
<div id="demo">
做个DEMO测试下
</div>

您可能感兴趣的文章:
css中filter滤镜,ie9 hack写法::root 选择器妙用
CSS 滤镜效果:模糊、灰度、亮度等
一个针对IE7的CSS Hack
CSS 浏览器兼容hack整理收藏
CSS3滤镜实现图片不同渲染效果例子
Js实现IE9下本地图片预览的代码举例
css中filter 滤镜详解
兼容IE6浏览器CSS背景半透明实例
IE10/11不支持条件性注释的3个解决方法
photoshop用置换滤镜制作逼真的毛巾字效果教程

[关闭]