Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to select second table's second row using CSS selectors

Tags:

html

css

I have an HTML table as below :

<table class="reference notranslate">
  <tr>..</tr>
     .
     .
  <tr>..</tr>
</table>
<table class="reference notranslate">
  <tr>..</tr>
     .
     .
  <tr>..</tr>
</table>
<table class="reference notranslate">
  <tr>..</tr>
     .
     .
  <tr>..</tr>
</table>

I know the XPATH : //table[@class = 'reference notranslate'][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?

like image 853
Arup Rakshit Avatar asked Jul 13 '13 20:07

Arup Rakshit


People also ask

How do I select every other row in CSS?

In the style, the "tr" selects the even table rows. You can use this css to select every other paragraph by changing the css to "p:nth-child(even)", or list items: li:nth-child(even), etc. Change "even" to "odd" if you want the shading to affect odd rows.

Can I select multiple elements at once with CSS?

When you group CSS selectors, you apply the same styles to several different elements without repeating the styles in your stylesheet. Instead of having two, three, or more CSS rules that do the same thing (set the color of something to red, for example), you use a single CSS rule that accomplishes the same thing.


2 Answers

"I know the XPATH : //table[@class = 'reference notranslate'][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?"

So, you mean like:

table.reference.notranslate:nth-child(2) tr:nth-child(2)

This selects the second descendant tr element of the second table which has both classes (reference and notranslate).

jsFiddle here.

like image 182
dsgriffin Avatar answered Sep 21 '22 08:09

dsgriffin


table.reference:nth-of-type(2) tr:nth-child(2)
{
    background-color:red;
}
like image 41
Nikola Mitev Avatar answered Sep 22 '22 08:09

Nikola Mitev