CSS 使包装 div 扩展到与内容 div 相同的高度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2321034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 21:36:48  来源:igfitidea点击:

Making wrapper div extend to same height as content divs

css

提问by jerrygarciuh

I have a wrapper div with a min-height set. Position is relative and display is block. I have two column divs floated left and set to inherit min-height.

我有一个最小高度集的包装 div。位置是相对的,显示是块。我有两列 div 向左浮动并设置为继承最小高度。

When I have lengthy content the background color of #wrapper never extends to match the content in the column divs.

当我有冗长的内容时,#wrapper 的背景颜色永远不会扩展以匹配列 div 中的内容。

Page is here: http://youngimaginations.dreamhosters.com/index.php

页面在这里:http: //youngimaginations.dreamhosters.com/index.php

CSS is here: http://youngimaginations.dreamhosters.com/yi.css

CSS 在这里:http: //youngimaginations.dreamhosters.com/yi.css

Can someone point out the error of my ways?

有人可以指出我方法的错误吗?

回答by Pekka

overflow: autowill do the trick

overflow: auto会做的伎俩

or a <div style='clear: both'>after the floated elements.

<div style='clear: both'>浮动元素之后。

回答by pixeline

The proper fix is called "clearfix".

正确的修复称为“clearfix”。

Read about it here, you'll never look back.

在这里阅读它,您将永远不会回头。