<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.
user22755177 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
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 ->
.item > div:first-child table { xxxx }
You can try this:
.item div:first-child table {XXX}
1