<div class="item">
<div><table>1</table></div>
<div><table>2</table></div>
<div><table>3</table></div>
</div>
I want to select the table which contains 1,below method doesn’t work:
All the table will be applied, why?
item table:nth-child(1) {
xxxx
}
doesnt work.
2
Answers
You can try this:
The selector
item table:nth-child(1)
doesn’t work as expected because:nth-child()
selects elements based on their position among siblings, not their overall position in the document structure.In your case, each is the first (and only) child of its parent , so all tables match :nth-child(1).
Final ans ->