码迷,mamicode.com
首页 > Web开发 > 详细

常见css的兼容问题

时间:2014-06-12 17:37:32      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

 1、链接的虚线框问题

bubuko.com,布布扣
<!-- html --><a class="noDashedBox" href="#"><img src="http://j5.dfcfw.com/image/201406/20140603152217.png" /></a>

/*
 * a, img, input等标签点击时会带有虚线框
 * 去除它
*/
.noDashedBox {
    outline:0;
    blr:expression(this.onFocus=this.blur());
}
bubuko.com,布布扣

2、固定定位

<!-- html -->
<a class="fixedTop" href="#"><img src="http://j5.dfcfw.com/image/201406/20140603152217.png" /></a>
 
<a class="fixedBottom" href="#"><img src="http://j5.dfcfw.com/image/201406/20140603152217.png" /></a>
bubuko.com,布布扣
/*  css  */
.fixedTop {
    position:fixed;
    top:100px;
    left:50%;
    margin-left:500px;
    _position:absolute;
    _top:expression(eval(document.documentElement.scrollTop + 100));
}
 
.fixedBottom {
    position:fixed;
    bottom:50px;
    left:50%;
    margin-left:500px;
    _position:absolute;
    _top:expression(eval(document.documentElement.scrollTop + document.documentElement.clientHeight - 70));
}
bubuko.com,布布扣

3、png背景图片透明:for ie6、

<!-- html -->
<div class="pngOpacity"></div>

css解决方案

bubuko.com,布布扣
/*
 * http://www.zhangxinxu.com/wordpress/2009/08/ +
 * ie6%E4%B8%8Bpng%E8%83%8C%E6%99%AF%E4%B8%8D%E9%80%8F%E6%98%8E%E9%97%AE%E9%A2%98%E7%9A%84%E7%BB%BC%E5%90%88%E6%8B%93%E5%B1%95/
 *
 * ie6 png8 background 不能定位
*/
.pngOpacity {
    height:228px;
    background:url(http://www.zhangxinxu.com/study/image/png_test.png) no-repeat;
    _background:none;
    _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=‘true‘, sizingMethod=‘crop‘, src=‘http://www.zhangxinxu.com/study/image/png_test.png‘);
}
bubuko.com,布布扣

js解决方案

bubuko.com,布布扣
// png透明的js解决方案  http://www.zhangxinxu.com/study/js/png.js
if (!window.XMLHttpRequest) {
    window.attachEvent("onload", enableAlphaImages);
}
 
function enableAlphaImages(){
    for (var i=0; i<document.all.length; i++){
            var obj = document.all[i];
            var bg = obj.currentStyle.backgroundImage;
            var img = document.images[i];
            if (bg && bg.match(/\.png/i) != null) {
                var img = bg.substring(5,bg.length-2);
                var offset = obj.style["background-position"];
                obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=‘"+img+"‘, sizingMethod=‘crop‘)";
                obj.style.background = "none";
        } else if (img && img.src.match(/\.png$/i) != null) {
            var src = img.src;
            img.style.width = img.width + "px";
            img.style.height = img.height + "px";
            img.style.filter ="progid:DXImageTransform.Microsoft.AlphaImageLoader(src=‘"+src+"‘, sizingMethod=‘crop‘)"
            img.src = "http://s1.95171.cn/b/img/pixel.gif"; //替换透明PNG的图片
 } } }
bubuko.com,布布扣

4、 opacity透明:整个元素透明,包括元素里面的内容

<!-- html -->
<div class="opacity"><span style="color:yellow;">this is opacity text</span></div>
 
<div class="opacity"><span style="color:yellow;position:relative;">this is text that not opacity in ie</span></div>
bubuko.com,布布扣
.opacity {
    background: #000;
    filter:alpha(opacity=50);
    *zoom:1;   /* sometimes it is needed */
    opacity: 0.5;
 
    font-size: 38px;
    color:#fff;    
}
bubuko.com,布布扣

5、rgba透明:只对背景透明,内容不会受到影响

<!-- html -->
<div class="rgbaAlpha">red green blue and alpha</div>
bubuko.com,布布扣
/* css */
.rgbaAlpha {
    width:300px;
    height:auto;
    padding:50px;
    filter:progid:DXImageTransform.Microsoft.gradient(startcolorstr=#7F000000,endcolorstr=#7F000000);
    background: rgba(0, 0, 0, 0.5);
 
    font-size: 38px;
    color:#fff;
}
bubuko.com,布布扣

 

常见css的兼容问题,布布扣,bubuko.com

常见css的兼容问题

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/jiangtuzi/p/3781994.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!