< ul>包含浮动时的高度< li>

问题描述:

我有一个列表:

<ul>
 <li>Number 1</li>
 <li>Number 2</li>
 <li>Number 3</li>
 ...
</ul>

所有< li> 。我需要< ul> 框的高度。如果我记得正确,这是无效的:

All the <li> are floating. I need the height of the <ul> box. If I remember correctly this is not valid:

<ul>
 <li>Number 1</li>
 <li>Number 2</li>
 <li>Number 3</li>
 ...
 <hr class="clear" />
</ul>

.clear {
   clear: both;
}

我该如何做?列表中的项目数可以不同,因此我不能使用固定高度。

How can I do this? The number of items in the list can be different so I can't use fixed height.

  • Add overflow: hidden to the ul.
  • Use clearfix.