简体   繁体   English

CSS显示:内联不适用于 <li> 元件

[英]css display:inline does not work on <li> element

I have this HTML: 我有这个HTML:

<div class="nav">
<ul class="nav-dots">
  <li class='ni n1'><a href="" class='nia'>dot</a></li>
  <li class='ni n2'><a href="" class='nia'>dot</a></li>
  <li class='ni n3'><a href="" class='nia'>dot</a></li>
</ul>
</div>

With this CSS: 使用此CSS:

.nav-dots {
   display: inline-block;
}

As you can see, the <li> elements should display inline, but, they don't, and I have no idea why. 如您所见, <li>元素应该以内联方式显示,但是它们没有显示,我也不知道为什么。 How can I fix this? 我怎样才能解决这个问题?

I made a jsfiddle 我做了一个jsfiddle

.nav-dots is a class added to the parent ul . .nav-dots是添加到父class ul You need to call display: inline; 您需要调用display: inline; on the li s themselves li Š自己

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

FIDDLE 小提琴

It should be 它应该是

.nav-dots li {
    display: inline-block;
}

or 要么

.ni {
    display: inline-block;
}

Your CSS is applying the inline-block display property to the ul, not the li children 您的CSS正在将内联块显示属性应用于ul,而不是li子级

also

.ni{display:inline}

will work 将工作

display is not a property that is inherited. display不是继承的属性。 In order to keep the same structure you have and make the list items inline, you have to explicitly set their display property to inherit : 为了保持相同的结构并使列表项内联,必须显式设置其display属性以inherit

li { list-style-type:none; display:inherit; }

Here's a jsFiddle 这是一个jsFiddle

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM