gpt4 book ai didi

html - 制作 :after element only if there is another element after it

转载 作者:技术小花猫 更新时间:2023-10-29 12:01:52 25 4
gpt4 key购买 nike

只有在元素后面有其他元素时,我才希望在元素之后有。到目前为止,这是我的代码:

<table id='table_1'>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
</table>

是否可以在 A 和 B 之后有 :after 而不是 C?

我的 CSS

#table_1 td:after{
content: "";
background: black;
border: 1px solid black;
position: relative;
margin-left: 10px;
}

最佳答案

最简单的方法是使用 not(:last-child):

#table_1 td:not(:last-child):after{
content: "";
background: black;
border: 1px solid black;
position: relative;
margin-left: 10px;
}

Working exmaple

这样你就有了只有一个选择器而且你不需要覆盖你的代码。

关于html - 制作 :after element only if there is another element after it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27764768/

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