我制作了一个页面,左侧有一个菜单,页面的其余部分有一些内容,底部有一个页脚。
如果我有一大堆文字作为内容,一切都完美无缺,因为这会将页脚向下推,并使页脚向左环绕菜单。这样,一切看起来和工作都完全符合我的要求。
但是,当内容只是一个小段落时,页脚没有被充分插入,它只是卡在菜单的右侧,就像内容一样。
这是我的问题的 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>
有什么方法可以使页脚位于菜单框下方,无论页面上有多少内容?
谢谢。
PS:我在这个网站上有 jQuery 和 jQueryUI,所以如果这些库可以提供某种解决方案,我可以使用它。
只需将 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>
我是一名优秀的程序员,十分优秀!