如何仅使用 CSS 使 HTML 列表水平显示而不是垂直显示? [英] How to make a HTML list appear horizontally instead of vertically using CSS only?

查看:17
本文介绍了如何仅使用 CSS 使 HTML 列表水平显示而不是垂直显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要这个是因为我想让菜单(由 HTML 列表组成)水平显示.

我不喜欢使用绝对定位,因为当我开始更改页面布局时它可能会变得混乱.

我还想删除子列表的缩进.可能吗?

解决方案

你将不得不使用类似下面的东西

#menu ul{列表样式:无;}#菜单里{显示:内联;}

I need this because I want to make a menu (which is made from a HTML list) appear horizontally.

I prefer not to use absolute positioning since it might become messy when I start changing the layout of the page.

I would like also to remove the indenting of the sub-lists. Is it possible?

解决方案

You will have to use something like below

#menu ul{
  list-style: none;
}
#menu li{
  display: inline;
}
	

<div id="menu">
  <ul>
    <li>First menu item</li>
    <li>Second menu item</li>
    <li>Third menu item</li>
  </ul>
</div>

这篇关于如何仅使用 CSS 使 HTML 列表水平显示而不是垂直显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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