【发布时间】:2014-06-25 21:16:59
【问题描述】:
好的,所以我有一个容器 div,其中包含两个左右浮动的 div。这些子 div 的高度取决于里面的内容(目前只是文本)。
问题是容器 div 的高度没有正确变化以适应孩子们;相反,它只适合右手 div 并且不适合左手。
我已将所有 div 的高度设置为自动。我也尝试将较大的子 div 的大小设置为 100%,但这似乎没有效果。
下面包含三个相关的 CSS(我还将提供网站链接,以便在需要时检查其余的 CSS 和 HTML)。
#container{
/*
The container, contains the page and the footer
*/
height: auto; /* this is the problem child...*/
width: 1000px;
margin: auto;
padding-top: 20px;
background-color: white;
}
#content{
/*
The container, contains the content of the webpage
*/
height: auto;
width: 600px;
margin: 10px 10px 0px 10px;
background-color: white;
float: left;
}
#aside{
/*
The aside to be used for additional information
*/
height: auto;
width: 330px;
float: right;
margin: 10px 10px 0px 10px;
padding: 5px 15px 5px;
background-color: #E8E8E8;
border-radius: 25px;
}
基本上我想要它,以便容器将是两个孩子中较高者的正确高度(但在这种情况下,我认为它始终是右手的)。但是目前它似乎总是匹配较小的。
可以看到的网站链接:http://timbrodrick.com/aboutWebsite.html “©2014 Tim Brodrick, info@timbrodrick.com”是页脚的一部分,它是一个从容器 div 末尾开始的 div。
【问题讨论】:
-
浮动元素就是这样——它们不会影响父元素的高度。您可以通过搜索关键字“clearfix”找到对抗这种行为的技术。