I have a relatively modular page but due to the CMS, the content for some of these paragraph blocks don't fill up the whole block, so I just want to increase the font size for some of the blocks. However, when I try to target 2 and 3, it doesn't seem to recognize it at all. In fact, it targets only the first one, and in my inspector, it says its because it's applying the rule for 2.
Example HTML
<div class="container">
<div class="item video">
<!-- HTML for video stuffs-->
</div>
<div class="item copy">
<h1>Example Title</h1>
<p>Example words</p>
</div>
<div class="item photo">
<!-- HTML for photo stuffs-->
</div>
<div class="item video">
<!-- HTML for video stuffs-->
</div>
<div class="item copy">
<h1>Example Title</h1>
<p>Example words</p>
</div>
<div class="item photo">
<!-- HTML for photo stuffs-->
</div>
<div class="item video">
<!-- HTML for video stuffs-->
</div>
<div class="item copy">
<h1>Example Title</h1>
<p>Example words</p>
</div>
<div class="item photo">
<!-- HTML for photo stuffs-->
</div>
<div class="item video">
<!-- HTML for video stuffs-->
</div>
<div class="item copy">
<h1>Example Title</h1>
<p>Example words</p>
</div>
<div class="item photo">
<!-- HTML for photo stuffs-->
</div>
</div>
Now my LESS file looks like this:
.container {
.item {
&.copy {
p {
font-size: 16px;
}
&:nth-of-type(2), &:nth-of-type(3) {
p {
font-size: 17px;
}
}
}
}
}
Theoretically, the paragraph text in the first and fourth .copy blocks should have a font size of 16px, while the second and third blocks should be 17px. However, what I'm seeing is that all of them are 16px and the first one is 17px, with it highlighted saying that it's because the rule for ".container .item.copy:nth-of-type(2) p" is overwriting it.
Why is the nth-of-type(2) rule targeting the first block of it's type and not the second? And why isn't the nth-of-type(3) rule not targeting the second block of it's type if that's how it's calculating them? I'm so confused as to what's happening here... Any help is much appreciated.