浏览器CSS兼容问题汇总及解决

来源:互联网 发布:mysql 最小id 查询 编辑:程序博客网 时间:2024/05/21 10:23

由于公司项目要求兼容到IE6,这之中遇到不少CSS兼容性问题,所以就在博客汇总下来,以后在项目中遇到新的兼容性问题,也会在这里更新。

1.IE6下height属性会失效

问题描述:在IE6下,即使块级元素设置了高度,但若元素内部的内容超出设置高度,内部内容会把该块级元素高度撑开,height失效。

解决方法:对该块级元素设置overflow:hidden;

 

2.div存在最小高度

问题描述:在IE6下,块级元素会存在大概是13px默认最小高度,即使是空的div标签或者height属性设置比13px小,也无济于事,这是因为IE6会默认font-size:13px;,即使是空div,也会被撑开,呈现13px的最小高度。

解决方法:设置font-size:0;或者overflow:hidden;

 

3.IE6下png图片背景不透明

问题描述:在IE7下,png图片背景会呈现灰色,而不是透明。

问题解决:解决方法有多种,我只列出我常用的两种:

     1.用插件解决,插件地址及调用方法如下所示:

[html] view plain copy
  1. <!--[if IE 6]>  
  2. <script src="http://img3.job1001.com/js/png.min.js" ></script>  
  3. <script>DD_belatedPNG.fix('.head img,.nav_phone img,.search,.qq img');  
  4. </script>  
  5. <![endif]-->  

2.将图片保存成gif格式

 

4.IE6下设置了position:absolute;的元素不显示

问题描述:IE6下,设置了position:absolute;的元素有可能不显示,原因未明。

问题解决:在该元素后面加个空的div标签,<div></div>

 

5.IE6下float:right;的元素会换行

问题描述:IE6下,同一行设置若干元素float:left;后若有元素设置float:right;,该元素会换行。

问题解决:foat:right;的元素放置在最前面

 

6.IE6下,line-height失效

问题描述:IE6下,当文字和img、input、textarea、select、等元素在同一个容器中的时候,line-height属性失效。只有全文字时,line-height属性才有效。

问题解决:在其中一个非文字的对象的样式中增加margin: (容器的line-height - 对象本身的高度)/2px 0;  和 vertical-align:middle;

 

7.IE6下,hover失效

问题描述:IE6下,hover只对a标签有效

问题解决:js代码解决

 

8.IE6不兼容position:fixed;

问题描述:IE6不支持position:fixed;

问题解决:1.JS代码解决

      2.css expression解决(备注:由于css expression极其影响性能,一般情况下不推荐使用),代码如下:

[css] view plain copy
  1. /* IE6 头部固定定位 */.fixed-top{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop));}  
  2. /* IE6 右侧固定定位 */.fixed-right{position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft+document.documentElement.clientWidth-this.offsetWidth)-(parseInt(this.currentStyle.marginLeft, 10)||0)-(parseInt(this.currentStyle.marginRight, 10)||0));}  
  3. /* IE6 底部固定定位 */.fixed-bottom{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop, 10)||0)-(parseInt(this.currentStyle.marginBottom, 10)||0)));}  
  4. /* IE6 左侧固定定位 */.fixed-left{position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft));}  

    这之中可能会出现抖动的情况,所以还需加入

[css] view plain copy
  1. /* 修正IE6抖动bug */_body{background-image:url(about:blank);background-attachment:fixed;} 
原创粉丝点击