我制作了一个左侧有菜单的页面,页面其余部分有一些内容,底部有一个页脚。
一切都很完美如果我有一个很大的文字内容作为内容,因为这将推下页脚,它将使页脚围绕左边环绕菜单。这样,一切都看起来和我的工作完全一样。
然而,当内容只是一个小段落时,页脚没有被推得足够,它只是挂在菜单的右边,就像内容一样。
这是我的问题的SSCCE:
* {
border:0;
margin:0;
padding:0;
}
#menu-box {
margin-left: 5px;
margin-top: 5px;
background-color: #E0E0E0;
float: left;
overflow: auto;
width: 120px;
}
#menu-box .menu-category {
font-weight: bold;
padding-left: 10px;
border-bottom: 1px solid #000000;
}
#menu-box .menu-item {
padding-left: 20px;
text-decoration: none;
}
#menu-box .menu-item a {
text-decoration: none;
}
#menu-box .menu-item a:hover {
text-decoration: underline;
}
#menu-box .selected {
font-weight: bold;
color: #000000;
}
#content
{
margin-bottom: 15px;
margin-left: 140px;
}
#footer {
margin-bottom: 10px;
padding: 10px;
border-top: 1px solid #909090;
}

<!DOCTYPE html>
<html>
<body>
<div id="menu-box">
<div class="menu-category">
<span>Section 1</span>
</div>
<ul>
<li><span class="menu-item"><a href="index.php">Item 1</a></span></li>
</ul>
<div class="menu-category">
<span>Section 2</span>
</div>
<ul>
<li><span class="menu-item selected">> Item 2 <</span></li>
<li><span class="menu-item"><a href="#">Item 3</a></span></li>
<li><span class="menu-item"><a href="#">Item 4</a></span></li>
<li><span class="menu-item"><a href="#">Item 5</a></span></li>
<li><span class="menu-item"><a href="#">Item 6</a></span></li>
</ul>
<div class="menu-category">
<span>Section 3</span>
</div>
<ul>
<li><span class="menu-item"><a href="#">Item 7</a></span></li>
<li><span class="menu-item"><a href="#">Item 8</a></span></li>
<li><span class="menu-item"><a href="#">Item 9</a></span></li>
<li><span class="menu-item"><a href="#">Item 10</a></span></li>
<li><span class="menu-item"><a href="#">Item 11</a></span></li>
</ul>
</div>
<div id="content">
<p>Some content here. Some content here. Some content here. Some content here. Some content here. Some content here. Some content here. Some content here.</p>
<p>Some content here. Some content here. Some content here. Some content here. Some content here. Some content here. Some content here.</p>
</div>
<div id="footer">
This is / should be the footer of the site
<br />
But it's too high and too much to the right of the page because the content is not sufficient to make it go UNDER the menu
</div>
</body>
</html>
&#13;
有什么办法可以让页脚位于菜单框下方,无论页面上有多少内容?
感谢。
PS:我在这个网站上有jQuery和jQueryUI,所以如果这些库可以提供某种解决方案,我可以使用它。
答案 0 :(得分:1)
#footer {
margin-bottom: 10px;
padding: 10px;
border-top: 1px solid #909090;
clear:both;
}
这就是你需要的。编辑css中的#footer,并使用clear:both;
进行更新。这将使它在所有浮动元素下面渲染,在这种情况下是左侧菜单。
答案 1 :(得分:1)
只需将clear: left;
添加到页脚。
* {
border:0;
margin:0;
padding:0;
}
#menu-box {
margin-left: 5px;
margin-top: 5px;
background-color: #E0E0E0;
float: left;
overflow: auto;
width: 120px;
}
#menu-box .menu-category {
font-weight: bold;
padding-left: 10px;
border-bottom: 1px solid #000000;
}
#menu-box .menu-item {
padding-left: 20px;
text-decoration: none;
}
#menu-box .menu-item a {
text-decoration: none;
}
#menu-box .menu-item a:hover {
text-decoration: underline;
}
#menu-box .selected {
font-weight: bold;
color: #000000;
}
#content
{
margin-bottom: 15px;
margin-left: 140px;
}
#footer {
clear: left;
margin-bottom: 10px;
padding: 10px;
border-top: 1px solid #909090;
}
<!DOCTYPE html>
<html>
<body>
<div id="menu-box">
<div class="menu-category">
<span>Section 1</span>
</div>
<ul>
<li><span class="menu-item"><a href="index.php">Item 1</a></span></li>
</ul>
<div class="menu-category">
<span>Section 2</span>
</div>
<ul>
<li><span class="menu-item selected">> Item 2 <</span></li>
<li><span class="menu-item"><a href="#">Item 3</a></span></li>
<li><span class="menu-item"><a href="#">Item 4</a></span></li>
<li><span class="menu-item"><a href="#">Item 5</a></span></li>
<li><span class="menu-item"><a href="#">Item 6</a></span></li>
</ul>
<div class="menu-category">
<span>Section 3</span>
</div>
<ul>
<li><span class="menu-item"><a href="#">Item 7</a></span></li>
<li><span class="menu-item"><a href="#">Item 8</a></span></li>
<li><span class="menu-item"><a href="#">Item 9</a></span></li>
<li><span class="menu-item"><a href="#">Item 10</a></span></li>
<li><span class="menu-item"><a href="#">Item 11</a></span></li>
</ul>
</div>
<div id="content">
<p>Some content here. Some content here. Some content here. Some content here. Some content here. Some content here. Some content here. Some content here.</p>
<p>Some content here. Some content here. Some content here. Some content here. Some content here. Some content here. Some content here.</p>
</div>
<div id="footer">
This is / should be the footer of the site
<br />
But it's too high and too much to the right of the page because the content is not sufficient to make it go UNDER the menu
</div>
</body>
</html>
答案 2 :(得分:0)
只需在<br style="clear:both">
<div id="footer">
即可
* {
border:0;
margin:0;
padding:0;
}
#menu-box {
margin-left: 5px;
margin-top: 5px;
background-color: #E0E0E0;
float: left;
overflow: auto;
width: 120px;
}
#menu-box .menu-category {
font-weight: bold;
padding-left: 10px;
border-bottom: 1px solid #000000;
}
#menu-box .menu-item {
padding-left: 20px;
text-decoration: none;
}
#menu-box .menu-item a {
text-decoration: none;
}
#menu-box .menu-item a:hover {
text-decoration: underline;
}
#menu-box .selected {
font-weight: bold;
color: #000000;
}
#content
{
margin-bottom: 15px;
margin-left: 140px;
}
#footer {
margin-bottom: 10px;
padding: 10px;
border-top: 1px solid #909090;
}
<!DOCTYPE html>
<html>
<body>
<div id="menu-box">
<div class="menu-category">
<span>Section 1</span>
</div>
<ul>
<li><span class="menu-item"><a href="index.php">Item 1</a></span></li>
</ul>
<div class="menu-category">
<span>Section 2</span>
</div>
<ul>
<li><span class="menu-item selected">> Item 2 <</span></li>
<li><span class="menu-item"><a href="#">Item 3</a></span></li>
<li><span class="menu-item"><a href="#">Item 4</a></span></li>
<li><span class="menu-item"><a href="#">Item 5</a></span></li>
<li><span class="menu-item"><a href="#">Item 6</a></span></li>
</ul>
<div class="menu-category">
<span>Section 3</span>
</div>
<ul>
<li><span class="menu-item"><a href="#">Item 7</a></span></li>
<li><span class="menu-item"><a href="#">Item 8</a></span></li>
<li><span class="menu-item"><a href="#">Item 9</a></span></li>
<li><span class="menu-item"><a href="#">Item 10</a></span></li>
<li><span class="menu-item"><a href="#">Item 11</a></span></li>
</ul>
</div>
<div id="content">
<p>Some content here. Some content here. Some content here. Some content here. Some content here. Some content here. Some content here. Some content here.</p>
<p>Some content here. Some content here. Some content here. Some content here. Some content here. Some content here. Some content here.</p>
</div>
<br style="clear:both">
<div id="footer">
This is / should be the footer of the site
<br />
But it's too high and too much to the right of the page because the content is not sufficient to make it go UNDER the menu
</div>
</body>
</html>