简体   繁体   English

我如何渲染<li>并排?

[英]How do I render <li> side-by-side?

I'm looking to create a navigation menu with list items rendered in one line.我希望创建一个导航菜单,其中包含一行呈现的列表项。 How do I do this?我该怎么做呢?

li {
    display: inline;
}

EDIT: I now realize why I felt strange answering with display: inline : because I usually use float: left myself instead, which is anthony-arnold's answer (so to him goes my upvote!).编辑:我现在意识到为什么我觉得用display: inline回答很奇怪:因为我通常使用float: left yourself 代替,这是 anthony-arnold 的回答(所以对他来说我赞成!)。

Anyway, while either method will cause your li s to display in one line, inline elements and floated elements do behave differently.无论如何,虽然任一方法都会导致您的li显示在一行中,但内联元素和浮动元素的行为确实不同。 Depending on how you've styled your layout, you may have to choose one or the other.根据您设置布局样式的方式,您可能必须选择其中一种。

You could also do this, for some situations:对于某些情况,您也可以这样做:

li {
    float: left;
}

My favorite way to do it it's by using because it's allow do use width, height, margins and padding:我最喜欢的方法是使用,因为它允许使用宽度、高度、边距和填充:

li { display: inline-block; }

But have some render problem in IE, to fix use (order is important):但是在 IE 中存在一些渲染问题,以修复使用(顺序很重要):

li 
{ 
  display: inline-block; 
  zoom: 1;
  *display: inline;
}

One of the best resources on the subject is http://css.maxdesign.com.au/listamatic/ (a little outdated though).关于该主题的最佳资源之一是http://css.maxdesign.com.au/listamatic/ (虽然有点过时)。

They suggest both li {display: inline;} and li {float: left;} depending on the effect you want.他们建议li {display: inline;}li {float: left;}取决于你想要的效果。

Look for example their "Simple horizontal list" http://css.maxdesign.com.au/listamatic/horizontal01.htm例如寻找他们的“简单水平列表” http://css.maxdesign.com.au/listamatic/horizo​​ntal01.htm

ul {
    float: right;  to <li> go to the Right or Left side
}

ul li {
    display: inline-block;
    padding: 10px;
    margin-top: 5px;
}

If you use the "float:" in the "li", the list will invert the sequency.如果在“li”中使用“float:”,则列表将反转顺序。

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

you will try this styling你会试试这个造型

li{
height:20px;
float:left;
list-style-type: none;
width:70px;
padding:3px;
border-right:1px solid #3687AF;
background-color: #015287;
background-repeat: no-repeat;
background-position: center 30px;
} 

it will work for u sure...它肯定对你有用...

You could do:你可以这样做:

li {
    float: left;
    display: inline;
}

If you want to maintain it's block characteristics but still need side-by-side, you could do:如果你想保持它的块特性但仍然需要并排,你可以这样做:

li {
    float: left;
    display: inline-block;
}

you can use float: left;你可以使用float: left;

ul li {
    float: left;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何并排创建3个相同大小的盒子? - How do I create 3 equal sized boxes side-by-side? 如何并排渲染li项目 - how to render li item side by side 如何在不指定宽度和大量数据或文本的情况下并排浮动两个div? - How do I float two divs side-by-side without specifying a width and large amount of data or text? 如何在不知道它们的尺寸的情况下并排在 flexbox 中使图像具有相同的高度 - How do I make images the same height in a flexbox side-by-side, without knowing their dimensions 如何在移动设备上堆叠两个div,但在桌面上并排放置呢? - How do I stack two divs on mobile but arrange side-by-side on desktop? 如何在整个屏幕宽度上并排两个div? - How do I span two divs side-by-side for the full screen width? 如何保持两个并排的 div 元素高度相同? - How do I keep two side-by-side div elements the same height? 如何在我的 Drupal 网站上并排嵌入 Instagram 帖子? - How do I embed Instagram posts on my Drupal website side-by-side? 2个div并排放置,一个漂浮-如何使另一个紧靠其附近而不重叠? - 2 divs side-by-side, one floated - how do I make the other fit next to it without overlapping? Ionic 5 表单布局 - 如何并排放置输入和 select - Ionic 5 form layout - How do I put input and select side-by-side
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM