且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何仅使用 CSS 使 HTML 列表水平显示而不是垂直显示?

更新时间:2023-02-25 14:34:30

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

#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>