我有一些浮動元素,比如除了內容區域之外還浮動的側邊欄。如果我沒有在側邊欄末尾添加<br clear="both"/>
,則頁腳和背景的某些部分變得很奇怪。浮動元素<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
我錯過了想到的任何快速解決方案?
謝謝。
編輯:例如,我希望邊框沒有間隙,背景也不應有空格。如果只是看起來像兩個部分:1)內容與側邊欄2)頁腳
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>layout</title>
<style type="text/css">
body {
margin:0;
padding:0;
}
#main {
background:#cfcfcf;
}
.inner {
margin: 0 auto;
padding: 96px 72px 0;
width: 1068px;
border-color: #000;
border-style: solid;
border-width: 0 1px;
color: #3C3C3C;
}
.post {
width: 705px;
background:#999;
float:left;
}
#comments, #respond {
background:#999;
}
#sidebar {
background:#777;
}
#footer {
clear:both;
background:gray;
}
</style>
</head>
<body>
<div id="main">
<div class="inner">
<div id="post" class="post">
<h2>Lorem Ipsum Test Page</h2>
<div class="entry">
<p>Lorem ipsum sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</div> <!-- entry -->
</div> <!-- post -->
<div id="sidebar">
<h2>Meta</h2>
<ul>
<li>Login</li>
<li>Anything</li>
</ul>
<h2>Subscribe</h2>
<ul>
<li>Entries (RSS)</li>
<li>Comments (RSS)</li>
</ul>
</div> <!-- sidebar -->
</div> <!-- inner -->
</div> <!-- main -->
<div id="footer">
<div class="inner">
Something
</div> <!-- inner -->
</div> <!-- footer -->
</body>
</html>
什麼是你的HTML和CSS代碼的div? – BoltClock 2011-01-12 20:28:48
好文章:http://css-tricks.com/all-about-floats/ – kapa 2011-01-12 20:34:23