• CSS完美兼容IE6/IE7/FF的通用方法


    一、CSS HACK
    以下两种方法几乎能解决现今所有HACK.

    1, !important

    随着IE7对!important的支持, !important 方法现在只针对IE6的HACK.(注意写法.记得该声明位置需要提前.)

    CSS代码
    1. <style>   
    2. #wrapper {   
    3. width100px!important/* IE7+FF */  
    4. width80px/* IE6 */  
    5. }   
    6. </style>  

    2, IE6/IE77对FireFox

    *+html 与 *html 是IE特有的标签, firefox 暂不支持.而*+html 又为 IE7特有标签.

    CSS代码
    1. <style>   
    2. #wrapper { width120px; } /* FireFox */  
    3. *html #wrapper { width80px;} /* ie6 fixed */  
    4. *+html #wrapper { width60px;} /* ie7 fixed, 注意顺序 */  
    5. </style>  

    注意:
    *+html 对IE7的HACK 必须保证HTML顶部有如下声明:

    XML/HTML代码
    1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  

    二、万能 float 闭合(非常重要!)

    关于 clear float 的原理可参见 [How To Clear Floats Without Structural Markup]
    将以下代码加入Global CSS 中,给需要闭合的div加上 class="clearfix" 即可,屡试不爽.

    CSS代码
    1. <style>   
    2. /* Clear Fix */  
    3. .clearfix:after {    
    4. content:".";    
    5. display:block;    
    6. height:0;    
    7. clear:both;    
    8. visibility:hidden;    
    9. }    
    10. .clearfix {   
    11. display:inline-block;   
    12. }   
    13. /* Hide from IE Mac \*/    
    14. .clearfix {display:block;}    
    15. /* End hide from IE Mac */    
    16. /* end of clearfix */  
    17. </style>  

    三、其他兼容技巧(再次啰嗦)

    1, FF下给 div 设置 padding 后会导致 width 和 height 增加, 但IE不会.(可用!important解决)
    2, 居中问题.
    1).垂直居中.将 line-height 设置为 当前 div 相同的高度, 再通过 vertical-align: middle.( 注意内容不要换行.)
    2).水平居中. margin: 0 auto;(当然不是万能)
    3, 若需给 a 标签内内容加上 样式, 需要设置 display: block;(常见于导航标签)
    4, FF 和 IE 对 BOX 理解的差异导致相差 2px 的还有设为 float的div在ie下 margin加倍等问题.
    5, ul 标签在 FF 下面默认有 list-style 和 padding . 最好事先声明, 以避免不必要的麻烦. (常见于导航标签和内容列表)
    6, 作为外部 wrapper 的 div 不要定死高度, 最好还加上 overflow: hidden.以达到高度自适应.
    7, 关于手形光标. cursor: pointer. 而hand 只适用于 IE.

    CSS代码
    1. /* FF */  
    2. .submitbutton {   
    3.  float:left;   
    4.  width40px;   
    5.  height57px;   
    6.  margin-top24px;   
    7.  margin-right12px;   
    8. }   
    9. /* IE6 */  
    10. *html .submitbutton {   
    11.  margin-top21px;   
    12. }   
    13. /* IE7 */  
    14. *+html .submitbutton {   
    15.  margin-top21px;   
    16. }  
    aliyun活动 https://www.aliyun.com/acts/limit-buy?userCode=re2o7acl
  • 相关阅读:
    使用 jfinal + beetl + bootstrap 实现商城展示及管理系统
    关于Node.js的__dirname,__filename,process.cwd(),./文件路径的一些坑
    canvas离屏、旋转效果实践——旋转的雪花
    走一步再走一步,揭开co的神秘面纱
    用javascript写一个emoji表情插件
    基于HTML5快速搭建TP-LINK电信拓扑设备面板
    百度地图获取规划路径信息
    devicePixelRatio 那些事儿
    怎样用JavaScript和HTML5 Canvas绘制图表
    首次写iPad布局感想(H5)
  • 原文地址:https://www.cnblogs.com/wangbin/p/1707983.html
Copyright © 2020-2023  润新知