父div不会随子div扩展

父div不会随子div扩展

本文介绍了父div不会随子div扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多这样的问题,但没有一个似乎有 position:absolute (可能是问题,不确定)
总是用于处理表格,现在在我第一次尝试使用div的时候遇到了以下问题。

I've seen many questions like this but none of them seem to have position:absolute in it (maybe that's the problem, not sure)Always used to work with tables and now in my first attempt with div's I've encountered the following issue.

我的主要问题是当我的一个孩子div #contentBox ),那么main-div( #container )不会扩展。

My main problem is that when one of my child-divs expands (#contentBox) then the main-div (#container) isn't expanding aswell.

如果您查看。

If you have a look at http://www.xact.be/consciente/index_v1.html all is well, once the div expands over the min-height of the #container-div it al goes haywire, see http://www.xact.be/consciente/index_v2.html for the issue.

不知道我是否编码错误,因此我要求您的专业知识: )

Not sure if i'm coding this all wrong or not, hence why i'm asking for your expertise :)

推荐答案

在极少数情况下,您应该只使用position:absolute。绝对定位Div会将其从页面的正常流程中移除,并中断正常的父/子关系。而是position:relative和div:right。然后添加适当的margin。您还需要从父div中删除不必要的绝对定位。使用float,padding和margin仅定位div。绝对定位最适合用于正常流动之外的事情。

You should only use position: absolute in rare cases. Absolute positioning a Div removes it from the normal flow of a page and disrupts the normal parent/child relationship. Instead position: relative the div and float: right. Then add the appropriate margin. You will also need to remove unnecessary absolute positioning from parent divs. Position the divs using float, padding and margin only. Absolute positioning is best used for things outside of the normal flow.

这篇关于父div不会随子div扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 04:17