< ul>包含浮动时的高度< li> [英] <ul> height when containing floating <li>

查看:122
本文介绍了< 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.

这篇关于&lt; ul&gt;包含浮动时的高度&lt; li&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆