How can I use “float: left” in a div without breaking the containing element's height?

前端 未结 6 2111
借酒劲吻你
借酒劲吻你 2020-12-10 18:49

It seems that floated HTML elements don\'t expand the heights of their containers. For example, consider the following code:

6条回答
  •  醉酒成梦
    2020-12-10 19:27

    You need to clear the float, which returns document flow back to normal. Use clear:left (or right, or both if such floats need to be cleared) on the last element that should reset the flow. Also read up on ClearFix. It should be noted that ClearFix can get a little sticky with IE... if you have control over the markup, sometimes it is safer to use the traditional clear.

提交回复
热议问题