简体   繁体   English

元素不扩展父元素高度

[英]Elements not extending parent element height

I have a container in which I'm putting a bunch of elements, and my expectation was that the container would expand downward as the container filled with elements. 我有一个容器,其中我放了一堆元素,我的期望是当容器充满元素时容器会向下扩展。 Unfortunately, this is not the case. 不幸的是,这种情况并非如此。 I have some div's that are floating over the edge of my container. 我有一些div漂浮在我的容器边缘。 I was able to remedy this with a bunch of break tags, but this was a sloppy solution. 我能用一堆破坏标签来解决这个问题,但这是一个草率的解决方案。

Perhaps my CSS is incorrect, but I can't figure out where. 也许我的CSS不正确,但我无法弄清楚在哪里。 The long select list and the major description should reside in the upper, white box. 长选择列表和主要描述位于上部白色框中。

Here's a Fiddle . 这是一个小提琴

EDIT: Uwe led me to research floats. 编辑:Uwe带我去研究花车。 I've discovered that floats are not considered in the normal flow layout. 我发现在正常流程布局中不考虑浮动。 So how is this fixable? 那怎么可以解决这个问题呢?

EDIT 2: I found a clearfix solution. 编辑2:我找到了一个clearfix解决方案。

.clearfix:after {
    content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}
.clearfix {
    display: inline-block;
}
* html .clearfix {
    height: 1%;
} /* Hides from IE-mac \*/
    .clearfix {
        display: block;
}

There are many ways to clear floats; 清除浮子的方法有很多种; simply appending overflow: hidden; 简单地追加overflow: hidden; to .main will solve your problem. .main将解决您的问题。

In practice though, it's probably better to directly clear the floats which are causing the problems rather than applying a fix to the parent div. 但实际上,最好直接清除导致问题的浮点数,而不是将修复程序应用于父div。 I would actually recommend appending the following properties to .bottom instead: 我实际上建议将以下属性添加到.bottom:

.bottom {
    clear: both;
    overflow: hidden;
}
  • clear: both takes care of clearing the floats in .content . clear: both负责清除.content的浮动。
  • overflow: hidden takes care of clearing the floats in .bottom overflow: hidden负责清除.bottom的浮动

You should also look into using the id attribute in addition to the class attribute for your HTML tags. 除了HTML标记的class属性之外,您还应该考虑使用id属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么绝对定位的元素会扩展父元素的高度 - Why is the absolutely positioned element extending the parent element's height 如何使两个元素都填充父元素(高度)? - How to make two elements both fill parent element (height)? CSS - 如何强制元素使用父元素的剩余/可用空间的 100% 而不超出它? - CSS - How to force elements to 100% of remaining/available space of parent element without extending beyond it? dd元素扩展了传递的父元素宽度 - dd element extending passed parent element width 父元素高度不继承 - Parent element height not inherited CSS:根据父元素调整一个元素的高度,保持其他元素的高度 - Css: adjust height of one element according to parent, keep height of other elements Iteriting <p> 元素获取其高度并使用其设置父LI元素的高度 - Iteriting <p> elements getting their height and using it to set height of parent LI element 当父元素的高度固定时,填写可变数量的子元素的高度 - Fill out the height of a variable number of child elements, when the parent element has a fixed height 防止元素扩展其父DIV - Prevent elements from extending their parent DIV 如何设置一个元素,使其使用父元素whilist上具有其他两个动态元素的剩余高度? - How to set an element so that it uses the remaining height of the parent element whilist having other 2 dynamic elements on it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM