Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当列表只有一个元素时,我想为列表项设置不同的样式,有没有办法只用 CSS 来做到这一点?
你想要的选择器是:only-child
:only-child
所以你可以在 css:li:only-child { }或p:only-child {}Apply-it 上使用你的元素
li:only-child { }
p:only-child {}