I have a HTML which users will enter.
Note: Markup HTML will never look like that. Sometimes this class room will move up, that class room will move down, so on and so forth. Or, they will add more class rooms.
My job is to look for "my-child" class names and style different colors for each my-child: my first child is red, second is green and third is blue.
Problem: I use first-of-type or nth-of-type() (I did use first-chil, too) they all don't work out. So that first-of-type, nth-of-type() or first-child or ~ are not a solution.
.school .my-child:first-of-type {
color: red;
}
.school .my-child:nth-of-type(2){
color: green;
}
.school .my-child:nth-of-type(3) {
color:blue;
}
<div class="school">
<div class="class-room">
<div class="other">Child</div>
</div>
<div class="class-room">
<div class="other">Child</div>
</div>
<div class="class-room">
<div class="other">Child</div>
</div>
<div class="class-room">
<div class="my-child">Child</div>
</div>
<div class="class-room">
<div class="other">Child</div>
</div>
<div class="class-room">
<div class="other">Child</div>
</div>
<div class="class-room">
<div class="other">Child</div>
</div>
<div class="class-room">
<div class="my-child">Child</div>
</div>
<div class="class-room">
<div class="other">Child</div>
</div>
<div class="class-room">
<div class="other">Child</div>
</div>
<div class="class-room">
<div class="my-child">Child</div>
</div>
<div class="class-room">
<div class="other">Child</div>
</div>
</div>
nth-child?nth-child, but that doesn't workhas(). Is JavaScript an option?.school .class-room:nth-of-type(4) .my-child { color: red; }?