2010-02-27 227 views
0

我遇到问题,需要一些帮助。嵌套Div不能正确堆叠内容

我有,看起来细一些的嵌套的div - 只要没有内容。一旦我添加了一些测试文本,由于页面可能有很多内容,间距出现在div之上。这里有一个链接到这个问题的截图:

http://www.stephencamper.com/screenshot/screenshot.gif

...这里是代码的样子:

html, body { 
 
    margin: 0; 
 
    padding: 0; 
 
    } 
 
    
 
    #wrap { 
 
    width: 1024px; 
 
    margin: auto; 
 
    } 
 
    
 
    #header { 
 
    width: 982px; 
 
    height: 98px; 
 
    margin: auto; 
 
    } 
 
    
 
    #body_container { 
 
    width: 982px; 
 
    } 
 
    
 
    #top_inner_bg { 
 
    width: 982px; 
 
    background: #FFF url(images/top_inner_bg.gif) no-repeat top; height: 9px; 
 
    } 
 
    
 
    #sides_inner_bg { 
 
    width: 982px; 
 
    background: #CCC url(images/vert_inner_bg.gif) repeat-x top; /* img ht is 2000px; it's supposed to fade transp after 770px; no sure if correct way to do this */ 
 
    } 
 
    
 
    #bot_inner_bg { 
 
    margin: auto; 
 
    width: 980px; 
 
    height: 100%; 
 
    background: #E8E7E3; 
 
    }
<div id="wrap"> 
 
    
 
    <!-- header --> 
 
     <div id="header"> 
 
     header here 
 
     </div> 
 
    
 
    <!-- body --> 
 
     <div id="body_container"> 
 
      <div id="top_inner_bg"> </div> 
 
     <div id="sides_inner_bg"> 
 
     <div id="bot_inner_bg"> 
 
       <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p> 
 
        <p>test</p>    
 
       </div> 
 
      </div> 
 
     </div> 
 
    
 
    </div>

我找了一个解决方案,并发现一些边缘溢出。我尝试了溢出:隐藏,但没有奏效。我的div也不漂浮,所以clearfix对我不起作用。当我为div添加边框时,它可以工作 - 但是,现在我有一个边框,而我不需要边框,因为我需要侧面图像与top_inner_bg div无缝连接。

请帮忙!

谢谢。

-Stephen

+0

你的截图返回403错误页面。 – 2010-02-27 11:50:38

+0

我得到了404。你也可能想限制你的服务器出错时浏览器吐出的东西。这样更紧张。 – volvox 2010-02-27 12:05:19

+0

这可能是由div上的css高度造成的 – GibboK 2015-02-14 14:37:17

回答

0

你挂不工作,所以我假定你的问题的图像是用的标题和第一p元素之间的空白量。我通过删除标题高度来解决这个问题,这导致它占用了大量的空白空间,并且我减小了下边距,这也增加了空白区域。

html, body { 
 
     margin: 0; 
 
     padding: 0; 
 
     } 
 

 
     #wrap { 
 
     width: 1024px; 
 
     margin: auto; 
 
     } 
 

 
     #header { 
 
     width: 982px; 
 
     /* Removed height: 98px; */ 
 
     margin: auto; 
 
     /* added margin-bottom*/ 
 
     margin-bottom: -2%; 
 
     } 
 

 
     #body_container { 
 
     width: 982px; 
 
     } 
 

 
     #top_inner_bg { 
 
     width: 982px; 
 
     background: #FFF url(images/top_inner_bg.gif) no-repeat top; height: 9px; 
 
     } 
 

 
     #sides_inner_bg { 
 
     width: 982px; 
 
     background: #CCC url(images/vert_inner_bg.gif) repeat-x top; /* img ht is 2000px; it's supposed to fade transp after 770px; no sure if correct way to do this */ 
 
     } 
 

 
     #bot_inner_bg { 
 
     margin: auto; 
 
     width: 980px; 
 
     height: 100%; 
 
     background: #E8E7E3; 
 
     }
<div id="wrap"> 
 

 
     <!-- header --> 
 
      <div id="header"> 
 
      header here 
 
      </div> 
 

 
     <!-- body --> 
 
      <div id="body_container"> 
 
       <div id="top_inner_bg"> </div> 
 
      <div id="sides_inner_bg"> 
 
      <div id="bot_inner_bg"> 
 
        <p>test</p> 
 
         <p>test</p> 
 
         <p>test</p> 
 
         <p>test</p> 
 
         <p>test</p> 
 
         <p>test</p> 
 
         <p>test</p> 
 
         <p>test</p>    
 
        </div> 
 
       </div> 
 
      </div> 
 
     </div>