문제

I may have random html......

<div>
<p></p>
<p></p>
....
<h1></h1>
<h1></h1>
...
<p></p>
<p></p>
....
</div>

Now, I want to count to heading as first second third etc child. For eg. if I set h1:first-child{} then it will not select as in the above example because it's not in first position of div.

So, how can I style assuming nth-child(1) for first h1 nth-child(2) for second h2 etc?

도움이 되었습니까?

해결책

You're looking for the :nth-of-type pseudo-class. h1:nth-of-type(5) will match the fifth h1 element, regardless of where it is.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top