CSS container div not getting height

后端 未结 6 553
佛祖请我去吃肉
佛祖请我去吃肉 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:42

    The best and the most bulletproof solution is to add ::before and ::after pseudoelements to the container. So if you have for example a list like:

    And every elements in the list has float:left property, then you should add to your css:

    .clearfix::after, .clearfix::before {
         content: '';
         clear: both;
         display: table;
    }
    

    Or you could try display:inline-block; property, then you don't need to add any clearfix.

提交回复
热议问题