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

后端 未结 7 887
夕颜
夕颜 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:30

    Firstly, I highly recommend you do your CSS styling in an external CSS file, rather than doing it inline. It's much easier to maintain and can be more reusable using classes.

    Working off Alex's answer (& Garret's clearfix) of "adding an element at the end with clear: both", you can do it like so:

        

    xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    zzzzzzzzzzzzzzzzzzzzzzzzzzzzz

    This works (but as you can see inline CSS isn't so pretty).

提交回复
热议问题