gpt4 book ai didi

html - 通过 CSS 选择器在所有 html 中选择标签的第一次和最后一次出现

转载 作者:太空宇宙 更新时间:2023-11-04 16:12:36 24 4
gpt4 key购买 nike

我有这个html标签

<div>
<ol>
<li>First</li>
<li>Foo</li>
<li>Foo</li>
<li>Foo</li>
</ol>
</div>
<div>
<ol>
<li>Foo</li>
<li>Foo</li>
<li>Foo</li>
<li>Last</li>
</ol>
</div>

我想更改整个 html 标签的前 li 和最后 li 的背景。我该怎么做?

我使用了这个 css,但它没有像我预期的那样工作

li:first-child {
background: #900
}

li:last-child {
background: #900
}

p.s 我需要在 IE8+ 上运行的解决方案。

jsfiddle

最佳答案

假设您的 HTML 结构不会改变,您可以:

div:first-child li:first-child {
background: #900;}

div:last-child li:last-child {
background: #900;}

关于html - 通过 CSS 选择器在所有 html 中选择标签的第一次和最后一次出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34158678/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com