Excluding first element in CSS [duplicate]

2020-04-02 08:05发布

Possible Duplicate:
How to skip first child?

I have a ul with 4 li in it:

<div id="someid">
    <ul>
       <li>1st</li>
       <li>2nd</li>
       <li>3rd</li>
       <li>4th</li>
    </ul>
</div>

I'm setting a style for these li elements:

#someid ul li{
      font-weight: bold;
}

Now I want exclude the first li. How can I do it?

2条回答
虎瘦雄心在
2楼-- · 2020-04-02 08:19
#someid ul li:not(:first-of-type) {
      font-weight: bold;
}

or if that doesn't work in ancient browsers:

#someid ul li {
      font-weight: bold;
}
#someid ul li:first-child {
      font-weight: normal;
}
查看更多
我只想做你的唯一
3楼-- · 2020-04-02 08:20

Use the CSS first-child selector:

#someid ul li:first-child { 
    font-weight: normal;
}
查看更多
登录 后发表回答