简体   繁体   English

垂直对齐列表项文本

[英]align list item text vertically

Is there a simple way to make the list items that take up two lines to align vertically with the text above? 有没有一种简单的方法可以使占用两行的列表项与上面的文本垂直对齐? Thanks 谢谢

* Cats            
* Turtles
* Frogs
* Horses and 
Zebras           
* Dogs
* Tigers and
Leopards

I want it to look like this 我希望它看起来像这样

* Cats            
* Turtles
* Frogs
* Horses and 
  Zebras           
* Dogs
* Tigers and
  Leopards

Using basic HTML list tags ( <ul> and <li> ) with a max-width CSS setting will let you do that. 将基本HTML列表标记( <ul><li> )与max-width CSS设置一起使用将使您做到这一点。 See this example: 请参阅以下示例:

 li { max-width: 75px; } 
 <ul> <li>Cats</li> <li>Turtles</li> <li>Frogs</li> <li>Horses and Zebras</li> <li>Dogs</li> <li>Tigers and Leopards</li> </ul> 

The correct way to do this is to use the list-style-position property. 正确的方法是使用list-style-position属性。 I limited the width of the list to show the behaviour if there is overflow by adding the <div class="surround"> , but it is for effect only. 我通过添加<div class="surround">来限制列表的宽度以显示是否存在溢出行为,但这仅是为了效果。 Read more on lists here: https://www.w3schools.com/css/css_list.asp 在此处阅读列表中的更多信息: https : //www.w3schools.com/css/css_list.asp

 ul { list-style-position:outside; } .surround { width:150px; } 
 <div class="surround"> <ul> <li>Cats</li> <li>Turtles</li> <li>Frogs</li> <li>Horses and Zebras</li> <li>Dogs</li> <li>Tigers and Leopards</li> </ul> </div> 

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

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