zoukankan      html  css  js  c++  java
  • css实现兼容各个浏览器的技巧

    IE6双倍边距问题
    在IE6中查看时,却会发现左侧外边距100像素,被扩大到200个像素,加上display: inline可解决;
    .floatbox {
      float: left;
       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" />

  • 相关阅读:
    channel 功能解析
    Docker 使用 Jenkins 镜像创建容器(转)
    使用Gson将Object转String出现u003d 的原因
    Gradle基础
    JAVA HashMap 和 HashSet 的区别
    ViewStub基本用法
    String类的内存分配
    区块链--资产数字化之路
    选择排序
    冒泡排序
  • 原文地址:https://www.cnblogs.com/jeffrey77/p/3057895.html
Copyright © 2011-2022 走看看