我有一個動態調整側欄div高度以匹配內容div的問題。 基於這裏的各種其他問題和谷歌搜索,我認爲沒有設置高度,它會使用父級div高度,但它似乎自動適合高度的內容,而不是。使用CSS動態調整DIV的大小
這可以在「baradineholdings.com.au」可以看出(請不要判斷網站,我是一個菜鳥,我更希望得到正常工作的基礎之前,我讓「漂亮」)。
主頁看起來很好,主要是因爲沒有內容。如果您前往關於頁面,您可以看到問題。我幾乎懷疑在主頁面的實例中,內容div取得了側欄div的高度,但我不知道爲什麼。
HTML;
<body>
<div id="wrapper">
<?php include('includes/header.php'); ?>
<div id="internal">
<div id="sidebar">
<h3>Navigation</h3>
<li><a href="index.php">Home</a></li>
<li><a href="about.php">About</a></li>
<li><a href="gallery.php">Gallery</a></li>
<li><a href="contact.php">Contact</a></li>
</div> <!-- end #sidebar -->
<div id="content">
<p>Images Coming Soon!</p>
<p>Please see the about page for more information.</p>
</div> <!-- end #content -->
</div> <!-- end #internal -->
<?php include('includes/footer.php'); ?>
</div> <!-- end #wrapper -->
</body>
CSS;
body {
background-color: #f1f1f1;
font-family: georgia,sans-serif;
color: #333;
margin: 0;
padding: 0;
}
#wrapper {
width: 960px;
background-color: #f1f1f1;
margin: 0 auto;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
}
#internal
{
width: 959px;
height: auto;
background-color: #f1f1f1;
margin: 0 auto;
border-right: 1px solid #ccc;
}
#content {
width: 675px;
height: auto;
float: left;
padding: 10px;
}
#sidebar {
width: 150px;
/* height: 410px; */
float: left;
background-color: #27408B;
color: white;
}
#sidebar a {
text-decoration: none;
color: white;
}
#sidebar li {
list-style: none;
}
正如我所說;菜鳥。所以我可能在這裏做一些愚蠢的事情...... 我試過jsfiddle,但即使在大約頁面中使用大量內容,它也會使它變小,因此它不會影響側邊欄... I已經在Chrome和IE中測試過,兩者都有相同的問題。
很好的鏈接。我也喜歡http://css-tricks.com/fluid-width-equal-height-columns/ – 2012-02-03 01:30:25
哈,這是一個很好的解決方法,我沒有想到這樣做! 謝謝:) – FizzBuzz 2012-02-03 04:12:23