admin管理员组文章数量:1295867
How can I add "," separated content: "," to all ul > li
not the last two lists
<style>
ul li:nth-last-child(2)::after { content: "," }
</style>
is not working
I've tried to separete all the li items with commas separeated except the last two item because the last one is hidden and the 2nd last one I don't want to show commas after it as it is the last item of shown li items.
How can I add "," separated content: "," to all ul > li
not the last two lists
<style>
ul li:nth-last-child(2)::after { content: "," }
</style>
is not working
I've tried to separete all the li items with commas separeated except the last two item because the last one is hidden and the 2nd last one I don't want to show commas after it as it is the last item of shown li items.
Share asked Feb 12 at 0:04 Altaf MalikAltaf Malik 131 silver badge6 bronze badges1 Answer
Reset to default 3You can use the :nth-last-child
to start counting from the bottom, along with :not()
:
ul li:not(:nth-last-child(-n + 2))::after {
content: ","
}
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
</ul>
<p>A couple more tests...</p>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
<p>Edge cases (elements < 4): These ones are tricky and it's up to you to tweak according to your requirements</p>
<ul>
<li>One</li>
<li>Two</li>
</ul>
<ul>
<li>One</li>
</ul>
本文标签: htmlHow not to access second last two elements by CSSStack Overflow
版权声明:本文标题:html - How not to access second last two elements by CSS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741628265a2389205.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论