首页 > css,如何选择部分几个元素?

css,如何选择部分几个元素?

<ul class=‘s1’>
  <li><a href='#'>雪碧</a></li>
  <li><a href='#'>可乐</li>
  <li><a href='#'>凉茶</li>
</ul>

我想只把前两个链接背景改成红色,即雪碧、可乐背景红,凉茶不变。
这句 .s1 a{background:red;}该如何修改?或者说该用哪种选择器?


.s1 a{
    background:red;
}

.s1 a:last-child {
  background: 你想设置的颜色;
}

或者
.s1 li:first-child a,.s1 li:nth-child(2) a {
 background:red;
}

.s1 li:not(:last-child) > a {
  background: red;
}

你的那个s1的引号好像写成汉子的单引号了。

.s1 li:first-child a,.s1 li:nth-child(2) a {
     background:red;
 }
 或者
 .s1>li:not(:last-child)>a {
     background: red;
 }
【热门文章】
【热门文章】