Select all 'tr' except the first one

2020-01-27 09:38发布

How can I select all tr elements except the first tr in a table with CSS?

I tried using this method, but found that it did not work.

10条回答
孤傲高冷的网名
2楼-- · 2020-01-27 10:20

Though the question has a decent answer already, I just want to stress that the :first-child tag goes on the item type that represents the children.

For example, in the code:

<div id"someDiv">
     <input id="someInput1" /> 
     <input id="someInput2" />
     <input id="someInput2" />
</div

If you want to affect only the second two elements with a margin, but not the first, you would do:

#someDiv > input {
     margin-top: 20px;
}
#someDiv > input:first-child{
     margin-top: 0px;
}

that is, since the inputs are the children, you would place first-child on the input portion of the selector.

查看更多
我想做一个坏孩纸
3楼-- · 2020-01-27 10:21

Since tr:not(:first-child) is not supported by IE 6, 7, 8. You can use the help of jQuery. You may find it here

查看更多
Luminary・发光体
4楼-- · 2020-01-27 10:24

You could also use a pseudo class selector in your CSS like this:

.desc:not(:first-child) {
    display: none;
}

That will not apply the class to the first element with the class .desc.

Here's a JSFiddle with an example: http://jsfiddle.net/YYTFT/, and this is a good source to explain pseudo class selectors: http://css-tricks.com/pseudo-class-selectors/

查看更多
趁早两清
5楼-- · 2020-01-27 10:25

Another option:

tr:nth-child(n + 2) {
    /* properties */
}
查看更多
登录 后发表回答