我有一個元素列表,其樣式以下: css
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>
輸出One | Two | Three | Four | Five |
One | Two | Three | Four | Five |
而不是One | Two | Three | Four | Five
One | Two | Three | Four | Five
html
任何人都知道如何選擇CSS除了最後一個元素? 瀏覽器
您能夠在此處查看 :not()
選擇器的定義 ide
每件事彷佛都是正確的 您可能但願使用如下css選擇器而不是您使用的css選擇器。 工具
ul > li:not(:last-child):after
使用CSS的示例 spa
ul li:not(:last-child){ border-right: 1px solid rgba(153, 151, 151, 0.75); }
你能夠試試這個,我知道不是你要找的答案,但概念是同樣的。 code
在哪裏爲全部孩子設置樣式,而後從最後一個孩子中刪除它。 orm
代碼片斷 htm
li margin-right: 10px &:last-child margin-right: 0
圖片 圖片
對我來講它工做得很好
&:not(:last-child){ text-transform: uppercase; }
您編寫的示例在Chrome 11中徹底適用於我。 也許你的瀏覽器不支持:not()
選擇器?
您可能須要使用JavaScript或相似工具來完成此跨瀏覽器。 jQuery在其選擇器API中實現:not() 。