2011-11-02 33 views
0

我有一个左浮动div与2行左浮动子块。每行都用一个简单的清除块清除。如何防止浮动子项的浮动父项在IE6中扩展为100%宽度?

问题是,IE6将父块的宽度扩展为可用空间的100%,而在其他浏览器中,父宽度设置为完全包裹子级。

当所有子块都浮动时,宽度在IE6中是正确的。但是我需要将儿童区块排成行,所以我在每行之后放置了一个额外的清晰区块。之后,父母的宽度扩大到100%。

有没有一种解决方法,在IE6中具有正常的父级块宽度? (表是不欢迎)

Have a look at the image illustrating the problem

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
<head> 
    <style type='text/css'> 
     #parent { 
      float: left; 
      background-color: black; 
     } 

     .block { 
      width: 30px; 
      height: 30px; 
      background-color: yellow; 
      margin: 10px;  
      float: left; 
     } 

     .clear { 
      height: 1px; 
      clear: both; 
      font-size: 1px; 
      line-height: 0px; 
     } 
    </style> 
</head> 

<body> 
    <div id="parent"> 
     <div class="block">1</div> 
     <div class="block">2</div> 
     <div class="block">3</div> 
     <div class="block">4</div> 

     <div class="clear"></div> 

     <div class="block">5</div> 
     <div class="block">6</div> 
     <div class="block">7</div> 
     <div class="block">8</div> 

     <div class="clear"></div> 
    </div> 
</body> 

回答

0

我没有获得IE6,所以我不能真正检查。但是你可以尝试以下方法:

http://jsfiddle.net/YA7CN/

(把块的容器有明确的:两者)

正如我所说的,它可能给你同样的问题...但它是一个选项。 顺便说一句,你是为使用ie6的特定公众设计的吗?如果不是这样,我不会太担心看起来不同的东西,你会生气地把所有东西都变成一个崩溃的东西,让它碰到一切!