Skip to main content
added 61 characters in body
Source Link
Nerdroid
  • 14.1k
  • 5
  • 62
  • 72

you could use first-of-type or nth-of-type(1) or nth-child(1 of .red)

.red { color: green; } /* .red:nth-of-type(1) */ /* .red:first-of-type */ .home :nth-child(1 of .red) { color: red; }
<div class="home"> <span>blah</span> <p>not red</p> <p class="red">first</p> <p class="red">second</p> <p class="red">third</p> <p class="red">fourth</p> </div>

you could use first-of-type or nth-of-type(1)

.red { color: green; } /* .red:nth-of-type(1) */ .red:first-of-type { color: red; }
<div class="home"> <span>blah</span> <p class="red">first</p> <p class="red">second</p> <p class="red">third</p> <p class="red">fourth</p> </div>

you could use first-of-type or nth-of-type(1) or nth-child(1 of .red)

.red { color: green; } /* .red:nth-of-type(1) */ /* .red:first-of-type */ .home :nth-child(1 of .red) { color: red; }
<div class="home"> <span>blah</span> <p>not red</p> <p class="red">first</p> <p class="red">second</p> <p class="red">third</p> <p class="red">fourth</p> </div>

Source Link
Nerdroid
  • 14.1k
  • 5
  • 62
  • 72

you could use first-of-type or nth-of-type(1)

.red { color: green; } /* .red:nth-of-type(1) */ .red:first-of-type { color: red; }
<div class="home"> <span>blah</span> <p class="red">first</p> <p class="red">second</p> <p class="red">third</p> <p class="red">fourth</p> </div>