Why doesn't the height of a container element increase if it contains floated elements?

后端 未结 7 909
情书的邮戳
情书的邮戳 2020-11-21 11:37

I would like to ask how height and float work. I have an outer div and an inner div that has content in it. Its height may vary depending on the content of the inner div but

相关标签:
7条回答
  • 2020-11-21 12:04

    Its because of the float of the div. Add overflow: hidden on the outside element.

    <div style="overflow:hidden; margin:0 auto;width: 960px; min-height: 100px; background-color:orange;">
        <div style="width:500px; height:200px; background-color:black; float:right">
        </div>
    </div>
    

    Demo

    0 讨论(0)
提交回复
热议问题