Heim  >  Artikel  >  Web-Frontend  >  10个常见的IE bug和解决方法_html/css_WEB-ITnose

10个常见的IE bug和解决方法_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:56:14998Durchsuche

1、IE6 幽灵文本(Ghost Text bug)

在我写本文之前,我遇到了这个bug。它相当的古怪和滑稽。一块不知哪来的重复的文本,被IE6显示在靠近原文本的下面。(译注:也可以参看 Explorer 6 Duplicate Characters Bug 获得bug演示)。我无法解决它,所以我搜索它,果然,这是另一个IE6的bug。

对此有许多解决方法,但是没有一个对我的例子有效(因为网站的复杂性我无法使用其中的一些方法)。所以我使用了hack。在原文本之后增加空格看起来能解决这个问题。

但是,从 Hippy Tech Blog 那里了解到,问题背后的原因是由于html注释标签。IE6不能正确的渲染它。下面是他建议的解决方案列表:

解决方法

  1. 使用标签包围注释
  2. 移除注释
  3. 在前浮动上增加样式 {display:inline;}
  4. 在适当的浮动的div上使用负边距
  5. 在原文本增加额外的 (比如10个空格) (hacky way)

2、相对位置和溢出隐藏(Position Relative and Overflow Hidden)

这个问题我遇到过很多次,当时我正在准备一个JQuery的教程,因为我使用了很多overflow hidden来达到我想要的布局。
问题发生在当父元素的overflow被设置成hidden并且子元素被设置成position:relative。
CSS-Trick有一个很好的例子来演示这个bug。position:relative and overflow in internet explorer

解决方法

为父元素增加position:relative;

3、IE的最小高度(Min-Height for IE)

这很简单,IE忽略min-height属性。你可以用下面的hack来修复它。感谢Dustin Diaz。

这个解决方法在IE6, Mozilla/Firefox/Gecko, Opera 7.x+, Safari1.2里都工作的很好。

解决方法

 

selector {  
    min-height:500px;  
    height:auto !important;  
    height:500px;  
}

 

4、Bicubic图像缩放(Bicubic Image Scaling)

你会喜欢这个的。IE那糟糕图像缩放让你很困扰?如果你拿IE和其他浏览器比较,IE缩小的图像看起来不如其他浏览器。

解决方法

 

img { -ms-interpolation-mode: bicubic; }

 

5、 PNG透明(PNG Transparency)

我猜每个人都知道这个,但我仍把它列在这里,作为以后的参考。
所以如果你想要使用透明图像并且GIF不能给你想要的质量,你会需要这个对PNG的hack。你必须意识到,如果你使用一张PNG图像作为背景,你将不能设置背景的位置。

解决方法:

 

img {  
    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(...);  
}

 

6、 IFrame透明背景 (IFrame Transparent Background)

在firefox和safari里你应该不会遇到这个问题因为默认情况下,iframe的背景被设置为transparent,但是在IE里,却不是如此。你需要用到allowTransparency 属性并且加入下面的CSS代码来达成目的。

解决方法

 

/* in the iframe element */  
 

/* in the iframe docuement, in this case content.html */  
body {
         
}

 

7、禁用IE默认的垂直滚动条(Disabled IE default Vertical Scroll bar)

默认情况下,即使内容适合窗口大小,IE(译注:IE6/7)也会显示垂直滚动条。你可以使用overflow:auto,让滚动条只在你需要时出现。

 

html {
    overflow: auto;  
}

 

8、:hover伪类(:hover Pseudo Class)

IE只支持元素的 :hover伪类。你可以使用jQuery的hover event来达到相同效果。

解决方法

 

/* jQuery Script */  
$('#list li').hover( 

    function () {  
        $(this).addClass('color');  
    }, 

    function() {  
        $(this).removeClass('color');  
    }  
); 

/* CSS Style */  
.color {  
        

/* HTML */  

      
       
  • Item 1
  •   
       
  • Item 2
  •   
       
  • Item 3
  •   

 

9、盒模型Hack(Box Hack Model)

这是IE里最热门的bug了。基本的理解是,IE计算宽度(width)的方式不同。基于w3c标准,一个元素总宽度应该是:
总宽度 = margin-left + border-left + padding-left + width + padding-right + border-right + margin-right
但是,IE计算宽度时没有加上填充和边框:
总宽度 = margin-left + width + margin-right

更多的细节,请参考这个链接:Internet Explorer和CSS盒模型详细解释

解决方法:

使用w3c的标准兼容模式。IE6或者之后的版本能基于w3c的标准计算,但是你仍旧会在IE5中遇到问题。

或者你可以用CSS Hack来解决这个问题。所有标准兼容的浏览器都能读取w\\idth:180px 除了IE5。

 

#content {  
    padding:10px;  
    border:1px solid;  
    width:200px;  
    w\\idth:180px;  
}

 

10、 双倍边距bug(Double Margin Bug Fix)

如果你有一个分配有左/右边距的浮动元素,IE6会使得边距双倍化。比如,margin-left:5px 将会变成10px。你可以通过对浮动元素添加display:inline来解决这个问题。

解决方法

 

div#content {  
    float:left;  
    width:200px;  
    margin-left:10px; 

    /* fix the double margin error */  
    display:inline;  
}

 

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn