常見css的相容問題

來源:互聯網
上載者:User

標籤:style   class   blog   code   java   http   

 1、連結的虛線框問題

<!-- 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());}

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>
/*  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));}

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

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

css解決方案

/* * 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‘);}

js解決方案

// png透明的js解決方案  http://www.zhangxinxu.com/study/js/png.jsif (!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的圖片 } } }

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>
.opacity {    background: #000;    filter:alpha(opacity=50);    *zoom:1;   /* sometimes it is needed */    opacity: 0.5;     font-size: 38px;    color:#fff;    }

5、rgba透明:只對背景透明,內容不會受到影響

<!-- html --><div class="rgbaAlpha">red green blue and alpha</div>
/* 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;}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.