我有一个动态调整侧栏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