1. css中几种浏览器对不同关键字的支持,可进行浏览器兼容性重复定义
!important 可被firefox和ie7识别
* 可被ie6、ie7识别
_ 可被ie6识别
*+ 可被ie7识别
区别ie6与ff:
background:orange;*background:blue;
区别ie6与ie7:
background:green !important;background:blue;
区别ie7与ff:
background:orange; *background:green;
区别ff,ie7,ie6:
background:orange;*background:green !important;*background:blue;
ie7,ie8兼容:
<meta http-equiv="x-ua-compatible" content="ie=emulateie7" />
2. 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]-->
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. 鼠标手势问题:firefox的cursor属性不支持hand,但是支持pointer,ie两个都支持;所以为了兼容都用pointer
5. firefox中设置html标签的style属性时,所有位置、宽高和尺寸值必须后跟px,ie也支持此写法,因此统一加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. 消除ul、ol等列表的缩进时,样式应写成:list-style:none;margin:0px;padding:0px;其中margin属性对ie有效,padding属性对firefox有效
8. css控制透明:ie:filter:progid:dximagetransform.microsoft.alpha(style=0,opacity=60); firefox:opacity:0.6;
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双线凹凸边框:ie:border: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. ie有select控件永远处于最上层的bug,且所有css对select控件都不起作用
13. ie支持form中的label标签,包括图片和文字内容;firefox不支持包含图片的label,点击图片不能让标记 label for 的radio或checkbox产生效果
14. firefox中的textarea不支持onscroll事件
15. firefox不支持display的inline和block
16. firefox对div设置margin-left, margin-right为auto时已经居中, ie中不行
17. firefox对body设置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>
这样可以避免一些访问过后的超链接就不具备hover和active样式了
19. ie中设置长段落自动换行在css中设置word-wrap:break-word;firefox中使用js插入 的方法来实现,具体代码如下:
<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)+ ;
strcontent=strcontent.substr(intlen,strcontent.length);
}
strtemp+= +strcontent;
obj.innerhtml=strtemp;
}
if(document.getelementbyid && !document.all) tobreakword(div_id, 37);
/* ]]> */
</script>
20. 在子容器加了浮动属性后,该容器将不能自动撑开
解决方法:在标签结束后下一个标签中加上一个清除浮动的css clear:both;