通过设置 的 display 属性为 inline,并清除 的默认浮动,以及为列表项设置宽度,可以将 html 中的无序列表水平排列。具体步骤包括:1. 将 设为内联元素;2. 清除 的默认浮动;3. 设置列表项的宽度。

HTML 无序列表横向排列方法
无序列表通常使用 <ul></ul> 标签创建,其列表项使用 <li> 标签标记。为了将无序列表横向排列,可以使用 CSS 中的 display 属性。
步骤:
1. 将 <ul></ul> 设为内联元素
立即学习“前端免费学习笔记(深入)”;
<code class="html"><ul style="display: inline;"></code>
2. 清除 <li> 的默认浮动
<li> 元素默认会浮动,这会破坏横向排列。可以通过 float: none 来清除浮动:
<code class="html"><li style="float: none;"></code>
3. 设置列表项的宽度
为了确保列表项水平排列,需要为它们设置宽度。可以使用 width 属性:
<code class="html"><li style="width: 150px;"></code>
示例代码:
<code class="html"><ul style="display: inline;"> <li style="float: none; width: 150px;">项目 1</li> <li style="float: none; width: 150px;">项目 2</li> <li style="float: none; width: 150px;">项目 3</li> </ul></code>
这样,无序列表中的项目将水平排列,宽度为 150 像素。











