gpt4 book ai didi

CSS 选择器 :last-child

转载 作者:太空宇宙 更新时间:2023-11-04 02:26:48 25 4
gpt4 key购买 nike

为什么第 3 个 a 元素不是 lightgreen 颜色?

<html>
<style type="text/css">
div.poncho {
background-color: #555;
font-size: 200%;
padding: 1em;
}
div.poncho a[poncho] {
color: bisque;
}
div.poncho a:first-child {
color: darkcyan;
}
div.poncho a:last-child {
color: lightgreen;
}
</style>

<body>
<div class="poncho">
<a poncho>poncho 1</a>
<br>
<a poncho>poncho 2</a>
<br>
<a poncho>poncho 3</a>
<br> <!-- if removed, it works as expected -->
</div>
</body>

最佳答案

在这种情况下,您可以使用 :last-of-type 选择器。

<html>
<style type="text/css">
div.poncho {
background-color: #555;
font-size: 200%;
padding: 1em;
}
div.poncho a[poncho] {
color: bisque;
}
div.poncho a:first-child {
color: darkcyan;
}
div.poncho a:last-of-type {
color: lightgreen;
}
</style>

<body>
<div class="poncho">
<a poncho>poncho 1</a>
<br>
<a poncho>poncho 2</a>
<br>
<a poncho>poncho 3</a>
<br> <!-- if removed, it works as expected -->
</div>
</body>

关于CSS 选择器 :last-child,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37198584/

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