Hayi
Hayi

Reputation: 6236

Select the first child element from many div

How Can I select the first child element in this case below :

<div class="root">

  <div class="child">1</div> <---- i want this element

</div>
<div class="root">

  <div class="child">2</div> 

</div>
<div class="root">

  <div class="child">3</div> 

</div>

i try the css below but i select all child elements

.child:first-child {
    ...
}

Upvotes: 0

Views: 35

Answers (1)

Simba
Simba

Reputation: 1651

If you want this just to affect the first root then you would also add a first-of-type to root

.root:first-of-type > .child:first-of-type {
   ...
}

Upvotes: 1

Related Questions