I have a HTML which users will enter. My job is to select "mychild" class names and style different colors for each mychild.
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-chil
are not a solution.
.parent .mychild:first-of-type {
text-decoration: underline;
background: yellow;
}
.parent .mychild:nth-of-type(2) {
text-decoration: underline;
background: red;
}
.parent .mychild:nth-of-type(3) {
text-decoration: underline;
background: green;
}
<div class="parent">
<div class="other">Child</div>
<div class="other">Child</div>
<div class="mychild">Child</div>
<div class="other">Child</div>
<div class="other">Child</div>
<div class="mychild">Child</div>
<div class="other">Child</div>
<div class="other">Child</div>
<div class="mychild">Child</div>
</div>