开发者

What's the condition for a div element to expand?

开发者 https://www.devze.com 2023-02-10 19:56 出处:网络
I have one div element where I have all articles. The articles itself are div-elements. <div id=\'articleContainer\'>

I have one div element where I have all articles. The articles itself are div-elements.

<div id='articleContainer'>
    <div class='article'></div>
    <div class='article'></div>
    <div class='开发者_如何学运维article'></div>
</div>

Here is the css for aritcleContainer

#articleContainer{
    position: relative;
    float:left;
    width: 600px;
    min-height: 600px;
    padding: 50px;
}

What's the least condition for it to expand as I add new articles? This example works but I just want to know the condition for it to expand for itself. There are other examples that do not expand for itself. Where I don't have a clue at all.


If the article elements are not floating elements, the contain will resize to contain them.

If the articles elements are floating elements, they will not affect the size of the container. You can add an overflow setting to the container to make it contain floating children:

#articleContainer{
    position: relative;
    float:left;
    width: 600px;
    min-height: 600px;
    padding: 50px;
    overflow: hidden;
}

Note that the overflow setting will not hide anything (unless you make the articles wider than 600 pixels), it's just used to change how the children are contained inside the element.

0

精彩评论

暂无评论...
验证码 换一张
取 消