How can I use “float: left” in a div without breaking the containing element's height?

前端 未结 6 2109
借酒劲吻你
借酒劲吻你 2020-12-10 18:49

It seems that floated HTML elements don\'t expand the heights of their containers. For example, consider the following code:

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 19:27

    Add overflow: auto on the containing element:

    .portfoliosite {
        background: #777;
        padding: 10px;
        width: 550px;
        overflow: auto;
    }
    .portfoliothumbnail {
        background: red;
        margin: 0 10px 10px 0;
        float: left;
        height: 150px;
        width: 150px;
    }

    AwesomeSite.Com

    An awesome site I did. It launched on Jan 1, 2009

    See: http://www.sitepoint.com/blogs/2005/02/26/simple-clearing-of-floats

提交回复
热议问题