gpt4 book ai didi

css - 检查 child 是否是最后一个 - 还包括文本节点

转载 作者:行者123 更新时间:2023-11-28 08:50:25 28 4
gpt4 key购买 nike

我想检查 parent child 是否是最后一个:(所以在我的例子中,如果它是父 .button 中的最后一个元素/节点,我想选择 .icon)

<a href="" class="button">
<i class="icon"></i>
Button
</a>
<a href="" class="button">
Button
<i class="icon"></i>
</a>

我这样试过:.button .icon:last-child:last-of-type

但是选择器会忽略文本节点 - 有没有办法检测 .icon 是否在文本之前/之后?

最佳答案

将文本节点放在元素中

.icon:last-child {
color: red;
}
<a href="" class="button">
<i class="icon">Not last child</i>
<span>Button</span>
</a><br />
<a href="" class="button">
<span>Button</span>
<i class="icon">Last child</i>
</a>

关于css - 检查 child 是否是最后一个 - 还包括文本节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46650496/

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