重叠的 Div——如何环绕?
我有一个大 div,其中包含几个动态 div。
它们通常被填充到左侧,并且位于另一个也被左侧填充的 div 内。
我想做的是让整个包含 div (它有一个边框)查看这些子 div 内部,并找到它需要扩展多大才能看起来像“包含”其所有子级。
有什么想法可以用一种优雅的方式来做到这一点吗?现在我已经有了一些艰难的组合,找到有问题的大 div,找到它的长度并添加其父项的所有 -left-padding。
I got a large div that is containing several dynamic divs inside of it.
They are often padded to the left and inside another div that is also padded left.
What I'm trying to do is have the overall containing div (it has a border) look inside these children divs and find how big it needs to expand itself in order to look like it's "containing" all its children.
Any ideas on a nice elegant way to do this? Right now I've got some hobbled together combination of finding the large div in question, finding its length and adding on all the -left-padding of its parents.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需在“整体包含 div”上设置 css 属性
overflow:hidden;
即可。这将使它自动扩展以包含其中的所有内容。just set the css property,
overflow:hidden;
on your "overall containing div". That'll make it automatically expand to contain all the stuff inside it.您可以使用 CSS clearfix。这非常适合将内容物漂浮在容器内。只需将代码保存到clearfix.css 并链接到您的html 中。
You could use a CSS clearfix. This is ideal for floating the contents inside a container. Just save the code to clearfix.css and link to that in your html.