【发布时间】:2018-07-30 16:11:00
【问题描述】:
是否可以将样式添加到第 n 个孩子到第 n 个孩子?
我正在处理一个学生列表(15 名学生),其中前 5 名学生的名字将变为绿色,然后 6-10 为橙色,11-15 为红色。
就像将 CSS 应用于一系列项目。
我找不到一些相关的问题。
希望你能理解我。
谢谢。
ol li:first-child{
color: green;
}
ol li:nth-child(2), ol li:nth-child(3), ol li:nth-child(4), ol li:nth-child(5){
color: green;
}
ol li:nth-child(6), ol li:nth-child(7), ol li:nth-child(8), ol li:nth-child(9), ol li:nth-child(10){
color: orange;
}
ol li:nth-child(11), ol li:nth-child(12), ol li:nth-child(13), ol li:nth-child(14), ol li:nth-child(15){
color: red;
}
<ol>
<li>student1</li>
<li>student2</li>
<li>student3</li>
<li>student4</li>
<li>student5</li>
<li>student6</li>
<li>student7</li>
<li>student8</li>
<li>student9</li>
<li>student10</li>
<li>student11</li>
<li>student12</li>
<li>student13</li>
<li>student14</li>
<li>student15</li>
</ol>
【问题讨论】:
-
你能分享你的代码吗?
-
刚刚添加了代码先生
标签: css css-selectors