I'm trying to apply some styles to some divs using nth-child
.
I have a misunderstanding about how those nth-child are working.
In CSS the hierarchy will be: ID, class, pseudo-classes but in my example the class is somehow ignored.
I have a parent div that have inside 7 children divs. First 3 children divs have a class kid1
, the next 4 divs have a class called kid2
.
.parent {
border: 1px solid orangered;
display: flex;
flex-flow: row nowrap;
height: 200px;
width: 80%;
}
.kid1 {
padding: 20px;
}
.kid1:nth-child(1) {
background: lime
}
.kid1:nth-child(2) {
background: blue
}
.kid1:nth-child(3) {
background: yellow
}
.kid2 {
padding: 20px;
}
.kid2:nth-child(1) {
background: orange
}
/*is counting starting with first element of the parent*/
.kid2:nth-child(4) {
background: red
}
.kid2:nth-child(3) {
background: red
}
.kid2:nth-child(4) {
background: cyan
}
<div class="parent">
<div class="kid1">FIRST</div>
<div class="kid1">FIRST</div>
<div class="kid1">FIRST</div>
<div class="kid2">SECOND</div>
<div class="kid2">SECOND</div>
<div class="kid2">SECOND</div>
<div class="kid2"></div>
</div>
The very strange part is on kid2 children divs because instead of starting counting from that class is start counting from verify first element and that will be kid1. Doesn't anybody know wth is acting like that?