【原创】整理浏览器对网页的兼容性问题(二)——CSS篇

二、            CSS兼容性:

 

1.        CSS中几种浏览器对不同关键字的支持,可进行浏览器兼容性重复定义

!important    可被FireFoxIE7识别

*                 可被IE6IE7识别

_                 可被IE6识别

*+               可被IE7识别

 

2.        IE专用的条件注释

  

<!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]-->

 

<!--[if IE]> 所有的IE可识别 <![endif]-->

 

<!--[if IE 5]> 仅IE5.0与IE5.5 <![endif]-->

 

<!--[if gt IE 5.0]> IE5.0以及IE5.0以上版本 <![endif]-->

 

<!--[if IE 6]> 仅IE6 <![endif]-->

 

<!--[if lt IE 6]> IE6以及IE6以下版本 <![endif]-->

 

<!--[if gte IE 6]> IE6以及IE6以上版本 <![endif]-->

 

<!--[if IE 7]> 仅IE7 <![endif]-->

 

<!--[if lt IE 7]> IE7以及IE7以下版本 <![endif]-->

 

<!--[if gte IE 7]> IE7以及IE7以上版本 <![endif]-->

 

3.        几个浏览器对实际像素的解释

 

IE/Opera:对象的实际宽度 = (margin-left) + width + (margin-right)

 

Firefox/Mozilla:对象的实际宽度= (margin-left) + (border-left-width) + (padding- left) + width + (padding-right) + (border-right-width) + (margin-right)

 

4.        鼠标手势问题:FireFoxcursor属性不支持hand,但是支持pointerIE两个都支持;所以为了兼容都用pointer

 

5.        FireFox中设置HTML标签的Style属性时,所有位置、宽高和尺寸值必须后跟pxIE也支持此写法,因此统一加px单位。如 Obj.Style.Height = imgObj.Style.Height + ‘px’;

 

6.        FireFox无法解析简写的padding属性设置,如padding 5px 4px 3px 1px;必须改为 padding-top:5px; padding-right:4px; padding-bottom:3px; padding-left:1px0

 

7.        消除ulol等列表的缩进时,样式应写成:list-style:none;margin:0px;padding:0px;

在IE中,设置margin:0px可以去除列表的上下左右缩进、空白以及列表编号或圆点,设置padding对样式没有影响;在Firefox中,设置margin:0px仅仅可以去除上下的空白,设置padding:0px后仅仅可以去掉左右缩进,还必须设置list-style:none才能去除列表编号或圆点。也就是说,在IE中仅仅设置margin:0px即可达到最终效果,而在Firefox中必须同时设置margin:0px、padding:0px以及list-style:none三项才能达到最终效果。

 

8.        CSS控制透明:IE

          -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; /*IE8*/ 

          filter:alpha(opacity=30);  /*IE5、IE5.5、IE6、IE7*/

        FireFox

          opacity: .3;  /*Opera9.0+、Firefox1.5+、Safari、Chrome*/

 

9.        CSS控制圆角:IE:不支持圆角;

FireFox: -moz-border-radius:4px;

-moz-border-radius-topleft:4px;

-moz-border-radius-topright:4px;

-moz-border-radius-bottomleft:4px;

-moz-border-radius- bottomright:4px;

 

10.    CSS双线凹凸边框:IEborder:2px outset;

FireFox

-moz-border-top-colors: #d4d0c8 white;

-moz-border-left-colors: #d4d0c8 white;

-moz-border-right-colors:#404040 #808080;

-moz-border-bottom-colors:#404040 #808080;

 

11.    IE支持CSS方法cursor:url()自定义光标样式文件和滚动条颜色风格;FireFox对以上两者均不支持

 

12.    IESelect控件永远处于最上层的bug,且所有CSSSelect控件都不起作用

 

13.    IE支持Form中的Label标签,包括图片和文字内容;FireFox不支持包含图片的Label,点击图片不能让标记 label for RadioCheckBox产生效果

 

14.    FireFox中的TextArea不支持onScroll事件

 

15.    FireFox对display的inline-block属性值不支持,而IE对display属性值均支持

 

16.    FireFoxDiv设置margin-left, margin-rightauto时已经居中, IE中不行

 

17.    FireFoxBody设置text-align, Div需要设置margin: auto(主要是margin-left margin-right) 方可居中

 

18.    对超链接的CSS样式设置最好遵从这样的顺序:L-V-H-A。即

<style type="text/css">
<!--
a:link {}
a:visited {}
a:hover {}
a:active {}
-->
</style>

这样可以避免一些访问过后的超链接就不具备hoveractive样式了

 

19.    IE中设置长段落自动换行在CSS中设置word-wrap:break-wordFireFox中使用JS插入&#10;的方法来实现,具体代码如下:

<script type="text/javascript">

/* <![CDATA[ */

function toBreakWord(el, intLen){

var obj=document.getElementById(el);

var strContent=obj.innerHTML;

var strTemp="";

while(strContent.length>intLen){

strTemp+=strContent.substr(0,intLen)+"&#10;";

strContent=strContent.substr(intLen,strContent.length);

}

strTemp+="&#10;"+strContent;

obj.innerHTML=strTemp;

}

if(document.getElementById && !document.all) toBreakWord("div_id", 37);

/* ]]> */

</script>

 

20.    在子容器加了浮动属性后,该容器将不能自动撑开

 

解决方法:在标签结束后下一个标签中加上一个清除浮动的CSS clear:both;

 

21.    浮动后IE6解释外边距为实际边距的双倍

 

解决办法:加上display:inline

 

22.    IE6下图片下方会有空隙

 

解决办法:为img加上display:block或设置vertical-align 属性为vertical-align:top | bottom |middle |text-bottom

 

23.    IE6下两个层中间有空隙

 

解决办法:设置右侧div也同样浮动float:left或者相对IE6定义 margin-right:-3px;

 

24.    LI中内容超过长度后以省略号的显示方法

<style type="text/css">

<!--

li {

width:200px;

white-space:nowrap;

text-overflow:ellipsis;

-o-text-overflow:ellipsis;

overflow: hidden;

}

-->

</style>

 

25.    将元素的高度和行高设为相同值,即可垂直居中文本

<style type="text/css">

<!--

div {

height:30px;

line-height:30px;

}

-->

</style>

 

26.    对齐文本与文本输入框,须在CSS中增加vertical-align:middle;属性设置

<style type="text/css">

<!--

… …

vertical-align:middle;

}

-->

</style>

 

27.    支持WEB标准的浏览器设置了固定高度值就不会像IE6那样被撑开,但是又想设置固定高度又想能够被撑开呢?解决办法是去掉height属性而设置min-height,为了兼容不支持min-heightIE6可以这样定义:

{

height:auto!important;

height:200px;

min-height:200px;

}

 

28.    web标准中IE无法设置滚动条颜色

 

解决办法:在CSS中对body的设置改为对html

<style type="text/css">

<!--

html {

scrollbar-face-color:#f6f6f6;

scrollbar-highlight-color:#fff;

scrollbar-shadow-color:#eeeeee;

scrollbar-3dlight-color:#eeeeee;

scrollbar-arrow-color:#000;

scrollbar-track-color:#fff;

scrollbar-darkshadow-color:#fff;

}

-->

</style>

 

29.    IE6由于默认行高问题无法定义1px左右高度的容器,

 

解决办法:在CSS中对容器设置如:overflow:hidden | zoom:0.08 | line-height:1px

 

30.    Flash设置透明属性可使层显示在Flash之上

 

<param name="wmode" value="transparent" />         <!-- 解决IE上的问题 //>

<embed wmode="transparent" …… >                     <!-- 解决FireFox上的问题 //>

 

31.    FireFox设置Padding属性后会相应的增加WidthHeight属性值,IE不会

 

解决办法:用!important方法多定义一套HeightWidth

 

32.    FireFoxdivdiv之间的空格是忽略的,但IE是处理的;因此尽量在两个相连的div之间不要有空格和回车,否则可能会造成不同浏览器之间格式不正确,比如著名的3px偏差;而且原因很难查明

 

33.    形如如下格式

<div id="parent">

<div id="content"> </div>

</div>

Content内容多时,即使parent设置了高度100%auto,在不同浏览器下还是不能完好的自动伸展;解决办法在层的最下方产生一个高度为1的空格,代码如下

<div id="parent">

<div id="content"> </div>

<div style="font: 0px/0px sans-serif;clear: both;display: block"> </div>

</div>

 

34.    IEFireFox对字体small的尺寸解释不同,FireFox13px,IE中为16px

 

35.    IEFireFox对空格的尺寸解释不同,FireFox4px,IE中为8px

 

36.    IE中支持在CSS中嵌入expresion,而Firefox不支持;firefox支持相邻子选择符">",而IE6不支持(IE7支持)

 

文止于此,由于作者才疏学浅,文中纰漏在所难免,欢迎大家批评指正、相互交流。

posted on 2008-10-20 19:55  hysoka  阅读(915)  评论(1编辑  收藏  举报

导航