1

i have a div that floats to left and another one that floats to right the main main div that including the floating div does not reach the bottom of the page and the code example is:

<div style=" width: 900px; height:auto; margin:5px auto; background:#666; ">
  <div style="float:left;">
  Some content! Some content! Some content! 
  </div>
  <div style="float:right;">
  Some content! Some content! Some content! 
  </div>
</div>

what is problem?

4

2 回答 2

6

The height of floated elements is not taken into account when the height of their parent element is calculated. You should look into the CSS property clear. In this case a third div with the CSS clear: both would help you achieve the result that you want.

但是,您应该退后一步,考虑一下您正在尝试做什么。如果您只是将这两个 div 彼此相邻,而在此级别没有其他框元素,则您可能不需要浮动这两个元素。

于 2013-03-29T22:01:17.260 回答
1

A container div with floating elements ignores the height of its children if you don't apply a clearfix to the container.

于 2013-03-29T21:59:44.913 回答