is there any way using a combination of pseudo classes like :nth-of-type
to style elements (eg. div) that are an nth occurence of this class in entire document? What I mean is not necessarily use this pseudo calss, but any method to target a specific occurence of a css class in entire website and not in the same parent.
Here is my code, which obviously doesn't work this way:
<html>
<head>
<style>
.a1:nth-of-type(1) div:nth-of-type(2) {background: red;}
.a1:nth-of-type(n+3) div:nth-of-type(2) {background: yellow;}
</style>
</head>
<body>
<div>
<div>
<div class="a1">
<div class="b1"><p>The first paragraph.</p></div>
<div class="b1"><p>The second paragraph.</p></div>
<div class="b1"><p>The third paragraph.</p></div>
<div class="b1"><p>The fourth paragraph.</p></div>
</div>
</div>
<br>
<div>
<div class="a1">
<div class="b2"><p>The first paragraph.</p></div>
<div class="b2"><p>The second paragraph.</p></div>
<div class="b2"><p>The third paragraph.</p></div>
<div class="b2"><p>The fourth paragraph.</p></div>
</div>
</div>
<br>
<div>
<div class="a1">
<div class="b3"><p>The first paragraph.</p></div>
<div class="b3"><p>The second paragraph.</p></div>
<div class="b3"><p>The third paragraph.</p></div>
<div class="b3"><p>The fourth paragraph.</p></div>
</div>
</div>
<br>
<div>
<div class="a1">
<div class="b4"><p>The first paragraph.</p></div>
<div class="b4"><p>The second paragraph.</p></div>
<div class="b4"><p>The third paragraph.</p></div>
<div class="b4"><p>The fourth paragraph.</p></div>
</div>
</div>
</div>
</body>
</html>
Here is the pen: http://codepen.io/kriana/pen/mOPrLd
Thanks!