Html 需要使用 CSS 选择器选择第二个表的第二行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17633959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Need to select second table's second row using CSS selectors
提问by Arup Rakshit
I have an HTMLtable as below :
我有一个HTML表,如下所示:
<table class="reference ">
<tr>..</tr>
.
.
<tr>..</tr>
</table>
<table class="reference ">
<tr>..</tr>
.
.
<tr>..</tr>
</table>
<table class="reference ">
<tr>..</tr>
.
.
<tr>..</tr>
</table>
I know the XPATH: //table[@class = 'reference '][2]/tr[2]
我知道XPATH://table[@class = 'reference '][2]/tr[2]
I want to select second table's second row. Can any one help how to write the CSS selectorsfrom the same?
我想选择第二个表的第二行。任何人都可以帮助如何从相同的地方编写CSS 选择器吗?
回答by dsgriffin
"I know the XPATH :
//table[@class = 'reference '][2]/tr[2]
I want to select second table's second row. Can any one help how to write the CSS selectors from the same?"
“我知道 XPATH :
//table[@class = 'reference '][2]/tr[2]
我想选择第二个表的第二行。任何人都可以帮助如何从相同的地方编写 CSS 选择器吗?”
So, you mean like:
所以,你的意思是:
table.reference.:nth-child(2) tr:nth-child(2)
This selects the second descendant tr
element of the second table which has both classes (reference
and ).
这将选择tr
具有两个类 (reference
和)的第二个表的第二个后代元素。
回答by Nikola Mitev
table.reference:nth-of-type(2) tr:nth-child(2)
{
background-color:red;
}