ie ff兼容问题好烦啊

ie与ff的兼容问题确实令人头痛呢,找了好多资料现在整理下吧:

 

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} p {mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋体; mso-bidi-font-family:宋体;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

所有浏览器 通用
height: 100px;

IE6 专用
_height: 100px;

IE6 专用
*height: 100px;

IE7 专用
*+height: 100px;

 

IE7 FF 共用
height: 100px !important;

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} p {mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋体; mso-bidi-font-family:宋体;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

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

1, !important ( 不是很推荐,用下面的一种感觉最安全)

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

代码:
<style>
#wrapper {
width: 100px!important; /* IE7+FF */
width: 80px; /* IE6 */
}
</style>

2, IE6/IE77FireFox <from 针对firefox ie6 ie7css 样式>

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

代码:
<style>
#wrapper { width: 120px; } /* FireFox */
*html #wrapper { width: 80px;} /* ie6 fixed */
*+html #wrapper { width: 60px;} /* ie7 fixed,
注意顺序 */
</style>

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

代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "">

二、万能 float 闭合( 非常重要!) 可以用这个解决多个div 对齐时的间距不对,

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

代码:
<style>
/* Clear Fix */
.clearfix:after {
content:".";
display:block;
height:0;
clear:both;
visibility:hidden;
}
.clearfix {
display:inline-block;
}
/* Hide from IE Mac /*/
.clearfix {display:block;}
/* End hide from IE Mac */
/* end of clearfix */
</style>

三、其他兼容技巧( 相当有用)

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

 

兼容代码 : 兼容最推荐的模式。
/* FF */
.submitbutton {
float:left;
width: 40px;
height: 57px;
margin-top: 24px;
margin-right: 12px;
}
/* IE6 */
*html .submitbutton {
margin-top: 21px;
}
/* IE7 */
*+html .submitbutton {
margin-top: 21px;
}

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} p {mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋体; mso-bidi-font-family:宋体;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

1 针对firefox ie6 ie7css 样式

现在大部分都是用!important 来兼容,对于ie6firefox 测试可以正常显示,但是ie7!important 可以正确解释,会导 致页面没按要求显示!找到一个针对IE7 不错的兼容方式就是使用“*+html” ,现在用IE7 浏览一下,应该没有问题了现在写一个CSS 可以这样:

#1 { color: #333; } /* Moz */
* html #1 { color: #666; } /* IE6 */
*+html #1 { color: #999; } /* IE*/

那么在firefox 下字体颜色显示为#333IE6 下字体颜色显示为#666IE7 下字体颜色显示为#999

2 css 布局中的居中问题

主要的样式定义如下:

body {TEXT-ALIGN: center;}
#center { MARGIN-RIGHT: auto; MARGIN-LEFT: auto; }

说明:

首先在父级元素定义TEXT-ALIGN: center; 这个的意思就是在父级元素内的内容居中;对于IE 这样设定就已经可以了。

但在mozilla 中不能居中。解决办法就是在子元素定义时候设定时再加上“MARGIN-RIGHT: auto;MARGIN-LEFT: auto; ”

需要说明的是,如果你想用这个方法使整个页面要居中,建议不要套在一个DIV 里,你可以依次拆出多个div ,只要在每个拆出的div 里定义MARGIN-RIGHT: auto;MARGIN-LEFT: auto; 就可以了。

3 盒模型不同解释.

#box{
width:600px;
//for ie6.0- w/idth:500px;
//for ff+ie6.0
}
#box{
width:600px!important
//for ff
width:600px;
//for ff+ie6.0
width /**/:500px;
//for ie6.0-
}

4 浮动ie 产生的双倍距离

#box{ float:left; width:100px; margin:0 0 0 100px; // 这种情况之下IE 会产生200px 的距离 display:inline; // 使浮动忽略}

这里细说一下block,inline 两个元素,Block 元素的特点是: 总是在新行上开始, 高度, 宽度, 行高, 边距都可以控制( 块元素);Inline 元素的特点是: 和其他元素在同一行上,… 不可控制( 内嵌元素);

#box{ display:block; // 可以为内嵌元素模拟为块元素 display:inline; // 实现同一行排列的的效果 diplay:table;

5 IE 与宽度和高度的问题

IE 不认得min- 这个定义,但实际上它把正常的widthheight 当作有min 的情况来使。这样问题就大了,如果只用宽度和高度,正常的浏 览器里这两个值就不会变,如果只用min-widthmin-height 的话,IE 下面根本等于没有设置宽度和高度。比如要设置背景图片,这个宽度是 比较重要的。要解决这个问题,可以这样:

#box{ width: 80px; height: 35px;}html>body #box{ width: auto; height: auto; min-width: 80px; min-height: 35px;}

6 页面的最小宽度

min-width 是个非常方便的CSS 命令,它可以指定元素最小也不能小于某个宽度,这样就能保证排版一直正确。但IE 不认得这个,而它实际上把 width 当做最小宽度来使。为了让这一命令在IE 上也能用,可以把一个<div> 放到 <body> 标签下,然后为div 指定一个类:
然后CSS 这样设计:

#container{
min-width: 600px;
width:e­xpression(document.body.clientWidth < 600? “600px”: “auto” );
}

第一个min-width 是正常的;但第2 行的width 使用了Javascript ,这只有IE 才认得,这也会让你的HTML 文档不太正规。它实际上通过Javascript 的判断来实现最小宽度。

7 清除浮动

. 兼容box{
display:table;
//
将对象作为块元素级的表格显示
}

或者

. 兼容box{
clear:both;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值