Make outer div be automatically the same height as its floating content

后端 未结 7 852
夕颜
夕颜 2020-11-29 00:03

I want the outer div, which is black to wrap its divs floating within it. I dont want to use style=\'height: 200px in the div

相关标签:
7条回答
  • 2020-11-29 00:51

    First of all you don't use width=300px that's an attribute setting for the tag not CSS, use width: 300px; instead.

    I would suggest applying the clearfix technique on the #outerdiv. Clearfix is a general solution to clear 2 floating divs so the parent div will expand to accommodate the 2 floating divs.

    <div id='outerdiv' class='clearfix' style='width:600px; background-color: black;'>
        <div style='width:300px; float: left;'>
            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
        </div>
    
        <div style='width:300px; float: left;'>
            <p>zzzzzzzzzzzzzzzzzzzzzzzzzzzzz</p>
        </div>
    </div>
    

    Here is an example of your situation and what Clearfix does to resolve it.

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