CSS container div not getting height

后端 未结 6 539
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 17:13

I want my container div to get the height of max of its children\'s height. without knowing what height the child divs are going to have. I was trying out on JS

6条回答
  •  春和景丽
    2020-11-30 17:35

    Add the following property:

    .c{
        ...
        overflow: hidden;
    }
    

    This will force the container to respect the height of all elements within it, regardless of floating elements.
    http://jsfiddle.net/gtdfY/3/

    UPDATE

    Recently, I was working on a project that required this trick, but needed to allow overflow to show, so instead, you can use a pseudo-element to clear your floats, effectively achieving the same effect while allowing overflow on all elements.

    .c:after{
        clear: both;
        content: "";
        display: block;
    }
    

    http://jsfiddle.net/gtdfY/368/

提交回复
热议问题