简体   繁体   English

列表样式未显示在水平列表上

[英]list-style not shown on horizontal list

I have a horizontal list in my markup with the following CSS: 我在使用以下CSS的标记中有一个水平列表:

ul li {
   display: inline;
   list-style: circle;
   list-style-type: circle;
}

When I remove the display: inline; 当我删除display: inline; it works fine. 它工作正常。 But I can't get it to work on the horizontal one. 但是我不能让它在水平框架上工作。

The list decorators will only be displayed if you don't override the display type for the list item. 仅当您不覆盖列表项的显示类型时,才会显示列表装饰器。 Rather than setting display: inline , apply a float: left and give some margin to prevent the circles from colliding into the previous element. 而不是设置display: inline ,而是使用float: leftfloat: left一些边距,以防止圆撞到上一个元素。

ul li {
  float: left;
  margin-left: 30px;
  list-style: circle;
  list-style-type: circle;
}

Here is an example. 这是一个例子。

 ul li { float: left; margin-left: 30px; list-style: circle; list-style-type: circle; } /* this bit is optional, it only removes the left padding from the first item */ ul li:nth-of-type(1) { margin-left: 0; } 
 <ul> <li> item 1 </li> <li> item 2 </li> <li> item 3 </li> <li> item 4 </li> </ul> 

well, if you do that it won't shw because you're basically declaring "stop displaying the element in its default display method list-item and use inline instead" . 好吧,如果这样做,它就不会消失,因为您基本上是在声明“停止在其默认显示方法list-item显示该元素,而是使用inline ”。 To learn more about display methods, please take a look do DISPLAY PROPERTY . 要了解有关显示方法的更多信息,请看一下DISPLAY PROPERTY

Now, if you want to have bullets AND still display it inline, there are many ways to do it. 现在,如果您想拥有项目符号并仍以嵌入式方式显示它,则有很多方法可以做到。 You can use a :before pseudo-selector, you can use a background, etc. 您可以使用:before伪选择器,也可以使用背景等。

For example: 例如:

ul li {
  display: inline;
}

ul li:before {
  content: "• ";
} 

or 要么

ul li{
  display: inline-block;
}

ul li{
  padding-left:30px; background:url(images/bullet.png) no-repeat 0 50% ;
}

but as long as you "kill" the list-item display method, you'll need to find some ways to override the DOM display of list types 但是只要您“杀死” list-item显示方法,就需要找到一些方法来覆盖列表类型的DOM显示

Instead of inline, use: 代替内联,使用:

li {
   float:left
}

or 要么

li {
   display:inline-block
}

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

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