If you need to reach your different classes, you need to go through the elements as indicated below. But the main thing is to have a link to the first element using the nth-child selector, I don’t see the need to worry about scripts, the code below works for me and applies different styles to different elements.
<style type="text/css">
section:nth-child(1) .major{
background:red;
height:100px;
color:#fff;
}
section:nth-child(2) .major{
background:blue;
height:100px;
color:lightcyan;
}
</style>
<section>
<header class="major">
<h2>Section 1</h2>
</header>
</section>
<section>
<header class="major">
<h2>Section 2</h2>
</header>
</section>
source
share