简体   繁体   English

样式不同颜色的列表项

[英]Styling list items with different colors

I'd like to style my list items with three different colors. 我想用三种不同的颜色为列表项设置样式。 What is the recommended way of doing that? 建议这样做的方法是什么?

My code so far: 到目前为止,我的代码:

 li { width: 33.333%; float: left; padding: 15px; list-style: none; } .light { background-color: #085dce; } .medium { background-color: #0051bb; } .dark { background-color: #004bad; } 
 <ul> <li>light-color</li> <li>medium-color</li> <li>dark-color</li> <li>light-color</li> <li>medium-color</li> <li>dark-color</li> <li>light-color</li> <li>medium-color</li> <li>dark-color</li> <li>light-color</li> </ul> 

Use nth-child to differ items. 使用nth-child来区分项目。

li:nth-child(3n+1) {background-color: #085dce;}
li:nth-child(3n+2) {background-color: #0051bb;}
li:nth-child(3n) {background-color:#004bad;}

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

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