2010-01-25 58 views
5

我有一个div,它具有固定的高度和背景颜色 - 正如您可以想象的背景颜色不会扩大以填充div的整个高度。获取背景颜色来填充div的全高

我也有4 div s在这个容器div圆角。我已经包含下面的代码。无论内容如何,​​我都可以将背景颜色扩展到容器div的底部?

#art2 { 
 
     margin-top: 15px; 
 
     margin-right: 10px; 
 
     float: right; 
 
     width: 485px; 
 
     background-color: #262626; 
 
    } 
 
    .art2boxtl { 
 
     background-image: url(../images/tlar2.png); 
 
     background-repeat: no-repeat; 
 
     height: 10px; 
 
     width: 9px; 
 
    } 
 
    .art2boxtr { 
 
     position: absolute; 
 
     right: 10px; 
 
     top: 15px; 
 
     background-image: url(../images/trar2.png); 
 
     background-repeat: no-repeat; 
 
     height: 10px; 
 
     width: 9px; 
 
    } 
 
    .art2boxbl { 
 
     position: absolute; 
 
     bottom: 0px; 
 
     background-image: url(../images/blar2.png); 
 
     background-repeat: no-repeat; 
 
     height: 11px; 
 
     width: 10px; 
 
    } 
 
    .art2boxbr { 
 
     position: absolute; 
 
     bottom: 0px; 
 
     right: 10px; 
 
     background-image: url(../images/brar2.png); 
 
     background-repeat: no-repeat; 
 
     height: 11px; 
 
     width: 10px; 
 
    }
<div id="art2"> 
 
    <div class="art2boxtl"></div> 
 
    <div class="art2boxtr"></div> 
 
    CONTENT 
 
    <div class="art2boxbl"></div> 
 
    <div class="art2boxbr"></div> 
 
</div>

回答

4

你的问题是不是background-color - ,将填补整个区域就好了 - 但是周围的DIV并没有扩展到所有DIV的全部大小理解它。

如果孩子是float: rightfloat: left,Raveren的方法将拉伸父母的div。它不适用于position:absolute。对于那些,你将不得不给父容器一个固定的高度。

2

的线路中试一下:

  <div id="art2"> 
       <div class="art2boxtl"></div> 
       <div class="art2boxtr"></div> 
       CONTENT 
       <div class="art2boxbl"></div> 
       <div class="art2boxbr"></div> 
       <div style="clear:both"></div> 
      </div> 

注意<div style="clear:both"></div>

+0

在这种情况下就不行,他含元素是'位置:absolute'。如果“float:left”或“right”这些元素是正确的 – 2010-01-25 17:56:25