2013-10-26 93 views
0

尽管内容中有内容,我的主域div仍然没有高度或宽度。我希望#main div填充页眉和页脚之间100%的空间,以便在整个页面(不包括页眉和页脚)中显示#main的背景图像。我一直无法获得#main动态填充整个空间(当浏览器窗口调整大小时,它应该调整大小)......我该如何做到这一点?即使内容有内容,内部div也有0x0大小

HTML:

<body> 
    <div id="page"> 
    <header id="header"> 
     <ul> 
      <li><a href="#">Item 1</a></li> 
      <li><a href="#">Item 2</a></li> 
      <li><a href="#">Item 3</a></li> 
      <li><a href="#">Item 4</a></li> 
      <li><a href="#">Item 5</a></li> 
     </ul> 
    </header> 

    <content id="main"> 
     <h1>Body</h1> 
     <p>Text...</p> 
    </content> 

    <footer id="footer"> 
     <ul> 
      <li><a href="#">Item 1</a></li> 
      <li><a href="#">Item 2</a></li> 
      <li><a href="#">Item 3</a></li> 
      <li><a href="#">Item 4</a></li> 
     </ul> 
    </footer> 
</div> 
</body> 

CSS:

#page { 
    min-height: 100%; 
    height: 100%; 
    position: relative; 
} 

#main { 
    padding-bottom: 50px; 
    background: url('Background.jpg'); 
} 

#header { 
    text-align: center; 
    background: #595959; 
    font-size: 30px; 
    line-height: 60px; 
} 

#header ul li { 
    display: inline-block; 
    height: 60px; 
    width: 19%; 
} 

#header ul li:hover, #footer ul li:hover { 
    background: #696969; 
} 

#header ul li a, #footer ul li a { 
    display: block; 
    text-decoration: none; 
    color: #BFBFBF; 
} 

#footer { 
    position: absolute; 
    height: 50px; 
    width: 100%; 
    bottom: 0; 
    text-align: center; 
    background: #595959; 
    font-size: 25px; 
    line-height: 50px; 
} 

#footer ul li { 
    display: inline-block; 
    height: 50px; 
    width: 15%; 
} 

#footer img { 
    margin-right: 10px; 
} 
+0

设置宽度为100%; –

+0

你试过我的建议吗?见下文… –

回答

0

添加到您的CSS ...

html, body { height: 100% } 

...,事情应该工作。

http://codepen.io/zitrusfrisch/pen/hDHrm

而且,是啊,你应该解决您的HTML作为<content>是不是一个有效的元素。请参阅笔以获取有效解

0

而不是使用此代码:

#main { 
    padding-bottom: 50px; 
    background: url('Background.jpg'); 
} 

body

body { 
    background: url('Background.jpg'); 
} 
#main { 
    padding-bottom: 50px; 
}