How to select the first child from all similar class in css
HTML
<div class="parent">
<div class="no-a-child"><span>1</span></div>
<div class="child"><span>2</span></div>
<div class="child"><span>3</span></div>
<div class="child"><span>4</span></div>
</div>
CSS
.parent .child:nth-child(1) span {
color:red;
}
.parent .child:nth-child(1) span {
color: red;
}
<div class="parent">
<div class="no-a-child"><span>1</span></div>
<div class="child"><span>2</span></div>
<div class="child"><span>3</span></div>
<div class="child"><span>4</span></div>
</div>
Here I want a red color:
<div class="child"><span>2</span></div>
element that is the second child of its parent:" using the code `p:nth-child(2) {background: red;}` So, you should use `nth-child(2)`
– theusaf Oct 11 '19 at 14:50