您的位置:首页 > Web前端 > CSS

css实现兼容各个浏览器的技巧

2013-05-03 21:38 363 查看
IE6双倍边距问题
在IE6中查看时,却会发现左侧外边距100像素,被扩大到200个像素,加上display: inline可解决;
.floatbox {
  float: left;
  width: 150px;
  height: 150px;
  margin: 5px 0 5px 100px;
  display: inline;
}

解决IE6不支持position:fixed;属性

常规 position:fixed; 实现方法
  例:右下角 <div id="top">...</div> 这个 HTML 元素使用的 CSS 代码如下:
  #top{
    position:fixed;
    bottom:0;
    right:10px;
  }
  实现让 <div id="top">...</div> 元素固定在浏览器的底部和距离右边的10个像素。

在 IE6中实现 position:fixed; 的办法
#top{
  position:fixed;
  _position:absolute;
  bottom:0;
  right:10px;
  _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))
);
在 _position:absolute; 中的 _ 符号只有 IE6 才能识别,目的是为了区分其他浏览器

使元素固定在浏览器的顶部:
#top{
  _position:absolute;
  _bottom:auto;
  _top:expression(eval(document.documentElement.scrollTop));


使元素固定在浏览器的底部:
#top{
  _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)));
}
这两段代码只能实现在最底部跟最顶部,可以使用 _margin-top:10px; 或者 _margin-bottom:10px; 修改其中的数值控制元素的位置

position:fixed; 闪动问题

用了上面的办法后,会发现:被固定定位的元素在滚动滚动条的时候会闪动。解决闪动问题的办法是在 CSS 文件中加入:
*html{
  background-image:url(about:blank);
  background-attachment:fixed;
}
其中 * 是给 IE6 识别的。

js解决ie兼容性

使IE5,IE6兼容到IE7模式(推荐)
<!--[if lt IE 7]>
<script src="http://ie7-js.googlecode.com/svn/version/2.0(beta)/IE7.js" type="text/javascript"></script>
<![endif]-->

使IE5,IE6,IE7兼容到IE8模式
<!--[if lt IE 8]>
<script src="http://ie7-js.googlecode.com/svn/version/2.0(beta)/IE8.js" type="text/javascript"></script>
<![endif]-->

使IE5,IE6,IE7,IE8兼容到IE9模式
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->

降级IE版本为7.0
<meta http-equiv="X-UA-ompatible" content="IE=EmulateIE7" />
另外;
<meta http-equiv="X-UA-Compatible" content="IE=7" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: