div+css通用兼容性代码整理

2020-05-02 07:56:24易采站长站整理

border:1px solid red;
}
–>
</style>
<div id=”ff”>aaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
<script type=”text/javascript”>
function toBreakWord(el, intLen){
var obj=document.getElementById(el);
var strContent=obj.innerHTML;
var strTemp=””;
while(strContent.length>intLen)
{
strTemp =strContent.substr(0,intLen) ” “;
strContent=strContent.substr(intLen,strContent.length);
}
strTemp =” ” strContent;
obj.innerHTML=strTemp;
}
if(document.getElementById && !document.all)
toBreakWord(“ff”, 37);
</script>

13.为什么IE6下容器的宽度和FF解释不同呢


<?xml version=”1.0″ encoding=”gb2312″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
<style type=”text/css”>
<!–
div {
cursor:pointer;
width:200px;
height:200px;
border:10px solid red
}
–>
</style>
<div ōnclick=”alert(this.offsetWidth)”>让FireFox与IE兼容</div>

问题的差别在于容器的整体宽度有没有将边框(border)的宽度算在其内,这里IE6解释为200PX ,而FF则解释为220PX,那究竟是怎么导致的问题呢?大家把容器顶部的xml去掉就会发现原来问题出在这,顶部的申明触发了IE的qurks mode,关于qurks mode、standards mode的相关知识,请参考:http://www.microsoft.com/china/msdn/library/webservices /asp.net/
ASPNETusStan.mspx?mfr=true

IE6,IE7,FF

IE7.0出来了,对CSS的支持又有新问题。浏览器多了,网Bpx; /*For IE7 & IE6*/
_height:20px; /*For IE6*/
注意顺序。
这样也属于CSS HACK,不过没有上面这样简洁。
#example { color: #333; } /* Moz */
* html #example { color: #666; } /* IE6 */
* html #example { color: #999; } /* IE7 */

第二种,是使用IE专用的条件注释


<!–其他浏览器 –>
<link rel=”stylesheet” type=”text/css” href=”css.css” />
<!–[if IE 7]>
<!– 适合于IE7 –>
<link rel=”stylesheet” type=”text/css” href=”ie7.css” />
<![endif]–>
<!–[if lte IE 6]>
<!– 适合于IE6及一下 –>
<link rel=”stylesheet” type=”text/css” href=”ie.css” />
<![endif]–>

第三种,css filter的办法,以下为经典从国外网站翻译过来的。.

新建一个css样式如下:


#item {