本文介紹了CSS :not(:last-child):after 選擇器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個元素列表,其樣式如下:
I have a list of elements, which are styled like this:
ul {
list-style-type: none;
text-align: center;
}
li {
display: inline;
}
li:not(:last-child):after {
content:' |';
}
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
</ul>
輸出 一個 |二 |三 |四 |五個 |
而不是 一個 |二 |三 |四 |五
有人知道如何通過 CSS 選擇除最后一個元素之外的所有元素嗎?
Anyone know how to CSS select all but the last element?
可以看到:not()
選擇器的定義這里
推薦答案
如果是not選擇器有問題,可以全部設置,覆蓋最后一個
If it's a problem with the not selector, you can set all of them and override the last one
li:after
{
content: ' |';
}
li:last-child:after
{
content: '';
}
或者如果你可以使用之前,不需要last-child
or if you can use before, no need for last-child
li+li:before
{
content: '| ';
}
這篇關于CSS :not(:last-child):after 選擇器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!