下面我們來處理幾個常見的CSS兼容性問題
一、鏈接的虛線框問題
復制代碼代碼如下:
<!-- Html -->
<a class="noDashedBox" href="#"><img src="image/201406/20140603152217.png" /></a>
復制代碼代碼如下:
/*
* a, img, input等標簽點擊時會帶有虛線框
* 去除它
*/
.noDashedBox {
outline:0;
blr:expression(this.onFocus=this.blur());
}
二、固定定位
復制代碼代碼如下:
<!-- Html -->
<a class="fixedTop" href="#"><img src="image/201406/20140603152217.png" /></a></p>< p><a class="fixedBottom" href="#"><img src="mage/201406/20140603152217.png" /></a>
復制代碼代碼如下:
/* CSS */
.fixedTop {
position:fixed;
top:100px;
left:50%;
margin-left:500px;
_position:absolute;
_top:expression(eval(document.documentElement.scrollTop + 100));
}</p>< p>.fixedBottom {
position:fixed;
bottom:50px;
left:50%;
margin-left:500px;
_position:absolute;
_top:expression(eval(document.documentElement.scrollTop + document.documentElement.clIEntHeight - 70));
}
三、png背景圖片透明:for IE6
復制代碼代碼如下:
<!-- Html -->
<div class="pngOpacity"></div>
復制代碼代碼如下:
/*
*
* IE6 png8 background 不能定位
*/
.pngOpacity {
height:228px;
background:url(image/png_test.png) no-repeat;
_background:none;
_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='crop', src='image/png_test.png');
}
復制代碼代碼如下:
// png透明的JS解決方案
if (!window.XMLHttpRequest) {
window.attachEvent("onload", enableAlphaImages);
}</p>< p>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 = "<a href="/School/UploadFiles_7810/201603/20160324203506391.gif</a>"; //替換透明PNG的圖片
} } }
四、opacity透明:整個元素透明,包括元素裡面的內容
復制代碼代碼如下:
<!-- Html -->
<div class="opacity"><span style="color:yellow;">this is opacity text</span></div></p>< p><div class="opacity"><span style="color:yellow;position:relative;">this is text that not opacity in IE</span></div>
復制代碼代碼如下:
/* CSS */
.opacity {
background: #000;
filter:alpha(opacity=50);
*zoom:1; /* sometimes it is needed */
opacity: 0.5;</p>< p> font-size: 38px;
color:#fff;
}
五、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);</p>< p> font-size: 38px;
color:#fff;
}