I want to change the style of the first element with class new. I've tried all nth-child/type methods but it doesn't seem to work.
* {
margin: 0;
box-sizing: border-box;
font-size: 1.2rem;
}
.new {
position: relative;
}
.new::before {
content: "";
position: absolute;
display: block;
left: -2rem;
width: 100%;
height: 100%;
background-color: gold;
z-index: -1;
}
.new::after {
content: "NEW";
color: green;
position: absolute;
font-weight: bold;
font-size: 0.5em;
display: inline-block;
margin-left: 1em;
}
.new:nth-of-type(1) {
background-color: blue;
}
<ol>
<li>item 1</li>
<li>item 2</li>
<li class="new">item 3</li>
<li class="new">item 4</li>
<li>item 5</li>
<li>item 6</li>
</ol>
I don't want to use JS.