首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > CSS >

【转】css各大兼容性~征集总结

2013-04-21 
【转】css各大兼容性~~收集总结}第一个min-width是正常的;但第2行的width使用了Javascrīpt,这只有IE才认得,

【转】css各大兼容性~~收集总结

}

第一个min-width是正常的;但第2行的width使用了Javascrīpt,这只有IE才认得,这也会让你的HTML文档不太正规。它实际上通过Javascrīpt的判断来实现最小宽度。

同样的办法也可以为IE实现最大宽度:
#container
{
min-width: 600px;
max-width: 1200px;
width:expression_r(document.body.clientWidth < 600? "600px" : document.body.clientWidth > 1200? ”1200px“ : ”auto";}

?

7、FF: 支持 !important, IE 则忽略
可用 !important (例:height:30px!important; height:26px;)为 FF 特别设置样式
div 的垂直居中问题: vertical-align:middle; 将行距增加到和整个DIV一样高 line-height:200px; 然后插入文字,就垂直居中了。缺点是要控制内容不要换行
cursor: pointer 可以同时在 IE FF 中显示游标手指状, hand 仅 IE 可以
FF: 链接加边框和背景色,需设置 display: block, 同时设置 float: left 保证不换行(背景图片需要设置 float: left )。参照 menubar, 给 a 和 menubar 设置高度是为了避免底边显示错位, 若不设 height, 可以在 menubar 中插入一个空格
在FF和IE中的BOX模型解释不一致导致相差2px解决方法:
div{margin:30px!important;margin:28px;}

注意这两个margin的顺序一定不能写反,!important这个属性IE不能识别,但别的浏览器可以识别。所以在IE下其实解释成这样:


div{maring:30px;margin:28px}

重复定义的话按照最后一个来执行,所以不可以只写margin:XXpx!important;


在Firefox/Mozilla 浏览器中,对象的实际宽度= (margin-left) + (border-left-width) + (padding- left) + width + (padding-right) + (border-right-width) + (margin-right);而在IE/Opera浏览器中,对象的实际宽度 = (margin-left) + width + (margin-right)。

?

?

构架中的兼容性

1、解决超链接访问过后hover样式不显示的问题


改变CSS属性的排列顺序: 先后顺序标准应为:a:link—a:visited—a:hover—a:active

2、Li中内容超过长度后以省略号显示的方法

<meta content="text/html; charset=gb2312" http-equiv="Content-Type" />

<style type="text/css">
<!--
li {
???? width:200px;
???? white-space:nowrap;????//定义列表不进行换行
???? text-overflow:ellipsis;??? //裁剪过长的文字同时添加“...”?但ff不认

??? ?-o-text-overflow:ellipsis;
???? overflow: hidden;}
-->

</style>
<ul>
???? <li><a href="#">web标准常见问题大全web标准常见问题大全</a></li>
???? <li><a href="#">web标准常见问题大全web标准常见问题大全</a></li>
</ul>

?

3、解决IE不能正确显示透明PNG——header内加入代码

程序代码<script language="javascript">
function correctPNG()
{
for(var i=0; i<document.images.length; i++)
{
?? var img = document.images[i]
?? var imgName = img.src.toUpperCase()
?? if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
?? {
??? var imgID = (img.id) ? "id='" + img.id + "' " : ""
??? var imgClass = (img.className) ? "class='" + img.className + "' " : ""
??? var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
??? var imgStyle = "display:inline-block;" + img.style.cssText
??? if (img.align == "left") imgStyle = "float:left;" + imgStyle
??? if (img.align == "right") imgStyle = "float:right;" + imgStyle
??? if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
??? var strNewHTML = "<span " + imgID + imgClass + imgTitle
??? + " style="" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
?? + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
??? + "(src=\'" + img.src + "\', sizingMethod='scale');"></span>"
??? img.outerHTML = strNewHTML
??? i = i-1
?? }
}
}
window.attachEvent("onload", correctPNG);
</script>?4、BOX模型在firefox和IE中的解释相差2px的解决方法
div{margin:30px!important;margin:28px;}
注意这两个margin的顺序一定不能写反。根据上面提到的IE并不支持!important,所以在IE下其实解释成这样:
div{maring:30px;margin:28px}

重复定义的话按照最后一个来执行,所以不可以只写margin:XXpx!important;
?5、去掉链接的虚线样式a{blr:e-xpression(this.onFocus=this.close()); text-decoration:none; color:#333;}?//针对ie
a:focus{-moz-outline-style:none;}?? //针对ff
a,area{blr:expression_r(this.onFocus=this.blur());}?? //针对ie 去点图片链接的虚线?6、ie6对line-height的失效在ie6中,当文字和img、input、textarea、select、object等对象在同一个容器中的时候,line-height属性失效。只有全文字时,line-height属性才有效。可以在其中一个非文字的对象的样式中增加: margin: (容器的line-height - 对象本身的高度)/2px 0;? vertical-align:middle; 解决问题。7、有时候两个div直接会产生缝隙可以在两个大的div中设置font-size:0px;然后再在里面一层的div中设置文字的正确大小?8.禁止选取网页内容
在IE中一般用js:obj.onselectstart=function(){return false;}
而ff用CSS:-moz-user-select:none;?9.CSS透明问题
IE:filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=60)。
FF:opacity:0.6;(最好两个都写,并将opacity属性放在下面。)?10.?关于手形光标cursor: pointer; //而hand 只适用于 IE?

11.用css控制图片大小

?? max-width:500px;??????//最大宽度为500

?? width:expression_r(this.width>500?"500px":this.width+"px");?//图片超过500,以500的宽度显示,

??????????????????????????????????????????????????????????????? 小于500则按原图大小显示

?

各个游览器的HACK

IE6 专用
_height: 100px;

IE6 IE7 共用
*height: 100px;

IE7 专用
*+height: 100px;

所以IE6、7、8 共用
height: 100px\9; (可以直接把ie和ff区别开)

IE7? FF 共用
height: 100px !important;

?

最新的ie8 可以直接把它打回ie7来显示

<meta http-equiv="X-UA-Compatible" content="IE=7"/>

?
css文字简写规律

font-weight:bold;??//宽度

font-style:italic;?//样式斜体

font-varient:small-caps;?//这个属性对中文字没有影响,是规定英文字母的大小

font-size:1em;??????//大小

line-height:1.5em;??//行高

font-family:verdana,sans-serif; //字体

?

但也可以把它们全部写到一行上去:

font: bold italic small-caps 1em/1.5em verdana,sans-serif;

这种简写方法只有在同时指定font-size和font-family属性时才起作用。而且,如果你没有设定font-weight, font-style, 以及 font-varient ,他们会使用缺省值

热点排行