您现在的位置是:网站首页> 编程资料编程资料
IE CSS Bug及解决方案参考手册 _CSS教程_CSS_网页制作_
                    
                
                2021-09-08
                1167人已围观
            
简介 作为一名前端,我们通常要做的就是让页面在各系统A-Grade浏览器,甚至网站浏览份额0.1%以上的浏览器上良好显示。
                当然,还有性能问题。不过,今天要说的是样式的兼容问题。在IE/Mozilla/Webkit/Opera四分天下的今天,IE6-9/Mozilla(Gecko)系列/Chrome/Safari/Opera etc. 这些浏览器的兼容,无不让前端们头痛。而在这之中,最让人头痛的当数IE,特别是IE6。搞定了IE6,基本也就能称霸半个江山了。搞定了IE,也相当于占领了7、80%的领地。你想做一个统治页面兼容的主么?反正我是想的。 
| 问题 | 浏览器 | DEMO | 解决方法 | |
|---|---|---|---|---|
| Hacking Rules:  
 property:all-ie\9; property:gte-ie8\0;*property:lte-ie7; +property:ie7; _property:ie6;  | ||||
| 1 | input[button | submit] 不能用 margin:0 auto; 居中 | IE8 | bug | fixed | 为input添加width | 
| 2 | body{overflow:hidden;}没有去掉滚动条 | IE6/7 | bug | fixed | 设置html{overflow:hidden;} | 
| 3 | hasLayout的标签拥有高度 | IE6/7 | bug | fixed | *height:0; _overflow:hidden;  | 
| 4 | form>[hasLayout]元素有margin-left时,子元素中的[input | textarea] 出现2×margin-left | IE6/7 | bug | fixed | form > [hasLayout 元素]{margin-left:宽度;} form div{*margin-left:宽度÷2;}  | 
| 5 | 当border-width有1条<边3条时被设置成dotted时,1px的边dotted显示成dashed | IE7 | bug | fixed | 不在同一个元素上使用不同宽度的 dotted | 
| 6 | 当子元素有position:relative的时候,父元素设置overflow:[hidden|auto]相当于给子元素设置了position:visible; | IE6/7 | bug | fixed | 给父元素设置position:relative; | 
| 7 | :hover伪类不能改变有position:absolute的子级元素的left/top值 | IE7 | bug | fixed | 把top/left的值设置成除0%外的所有百分值;或添加一个margin-[所有方向]除0外的所有值,包括0% | 
| 8 | :focus + selector {} 选择器失效 | IE8 | bug | fixed | 在失效选择器后面添加一个空选择器, :focus{} | 
| 9 | 列表中混乱的浮动:在list中浮动图片时,图片出现溢出正常位置;或没有list-style | IE8 | bug | fixed | 用背景图片替换list-style | 
| 10 | th 不会自动继承上级元素的 text-align | IE8 | bug | fixed | 给th添加text-align:inherit; | 
| 11 | 样式(包括link/style/@import(link)) 最多允许个为是:32 | IE6-8 | ─ 常识 | 99.99%的情况下,不会遇到 | 
| 12 | :hover 时若background-color为#fff, 失效 | IE7 | bug | fixed | 把background-color改成background。或者,非#fff || #ffffff | 
| 13 | 忽略’>’后有注释的选择器:selector> /**/ selector{} | IE7 | bug | fixed | 官方DEMO有误 | 
| 14 | * html | IE6 | ─ HACK | 只对IE6有效 | 
| 15 | PNG图片中的颜色和背景颜色的值相同,但显示不同 | IE6-7 | bug | fixed | 利用 pngcrush 去除图片中的 Gamma profiles | 
| 16 | margin:0 auto; 不能让block元素水平居中 | IE6-8 | bug | fixed | 给block元素添加一个width | 
| 17 | 使用伪类 :first-line | :first-letter, 属性的值中出现!important 会使属性失效 | IE8 | bug | fixed | !important is evil, don’t use it anymore | 
| 18 | :first-letter 失效 | IE6 | bug | fixed | 把 :first-letter 移到离{}最近的地方,如 h1, p:first-letter{},而非 p:first-letter h1{} | 
| 19 | Position:absolute元素中,a display:block, 在非:hover时只有文本可点击 | IE6/7 | bug | fixed | 给a添加background, 如果背景透明,使用background:url(‘任何页面中已经缓存的文件链接’),不推荐background:url(#)[官方的解决方法],因为会增加一下HTTP请求 | 
| 20 | float列表元素不水平对齐:li不设置float,a设置display:block;float:[方向],li不水平对齐 | IE6/7 | bug | fixed | 给li设置display:inline 或 float:[方向] | 
| 21 | dt, dd, li 背景失效 | IE6 | bug | fixed | dt, dd, li{position:relative;} | 
| 22 | 元素的样式在启用javascript的情况下显示了样式 | IE6-8 | bug | fixed | 利用js给添加display:none; | 
| 23 | 使用filter处理的透明背景图片的透明部分不可点 | IE6-8 | bug | fixed | 把background:none变成background:url(‘链接’),链接到本身和图片之外的任何文件 | 
| 24 | li内元素偏离 baseline 向下拉 | IE8 | bug | fixed | 给li设置display:inline 或 float:[方向] | 
| 25 | 列表中li的list-style不显示 | IE6/7 | bug | fixed | 给li添加margin-left,留空间来显示(不要加在ul上) | 
| 26 | 图片不能垂直居中 | IE6/7 | bug/fixed | 添加一个空标签,并赋给”Layout”, 比如display:inline-block; | 
| 27 | 不能自定义指针样式 | IE6-8 | bug | fixed | 给指针文件设置绝对路径 | 
| 28 | 背景溢出,拖动滚动条后显示正常 | IE6 | bug | fi
                
                 
 相关内容
 点击排行本栏推荐 
 | |
                                
                                                        
                                
                                                        
                                
                                                        
    