PIE使用阴影后的背景透明方法

使用PIE后,会发现如果有设置 box-shadow 时,当前 class 样式中设置 opacity 或者背景渐变透明都会无效了,其实也是有办法解决的

css3-container { filter:alpha(opacity=80); }
#header-wrapper { 
    height:35px;
    background: -webkit-gradient(linear,left top,left bottom,from(rgba(68,102,113,0.9)),to(rgba(46,74,83,0.9)));
    background: -moz-linear-gradient(top, rgba(68,102,113,0.9), rgba(46,74,83,0.9));
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#E6446671', endColorstr='#E62E4A53'); /* IE6,IE7 */
    -ms-filter:"progid:DXImageTransform.Microsoft.gradient(startColorstr='#E6446671', endColorstr='#E62E4A53')"; /* IE8 */
    box-shadow:0 1px 3px #000;
}

上面这个例子中使用背景渐变透明,但因为有 box-shadow 导致透明失效,这个时候需要添加个样式

css3-container { filter:alpha(opacity=80); }

就可以让 IE 实现阴影的同时也能背景透明了,不过这样写有个问题就是全部的PIE兼容都会透明,所以最好的办法是有两个:


1. css 中指定某个具体节点下的 css3-container 透明

这个方法很多时候不好控制,主要是老版本的 IE 的选择器不好控制

2. 通过 jQuery 动态添加样式,建议这个方法

只需要找到当前需要兼容的 div 然后找到他的上一个 css3-container 就可以了

例:

$('.curr').prev('css3-container').css('filter', 'alpha(opacity=80)');

这样就可以了


另说明:

对浅色如白色之类的背景透明可能效果不是很好,因为PIE的阴影会生成一个全黑的 css3-container 即时使其透明,浅背景色可能显示效果不太好吧

posted @ 2014-02-03 14:27  神神的蜗牛  阅读(182)  评论(0编辑  收藏  举报