1
If I take the first paragraph containing the class .oculta works, but otherwise the selector nth-child does not work. Both the nth-child as to the first-child do not work for some reason, even though everything seems to be right.
I want to catch the first occurrence of a certain class.
.oculta {
display: none;
}
.mostra:first-child {
background: brown
}
<p class="oculta">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Temporibus repudiandae perferendis adipisci, reprehenderit ipsam, accusantium ea nulla consequatur, quam exercitationem cumque explicabo! Officiis consectetur culpa ducimus, quo quam officia omnis?</p>
<p class="mostra">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Temporibus repudiandae perferendis adipisci, reprehenderit ipsam, accusantium ea nulla consequatur, quam exercitationem cumque explicabo! Officiis consectetur culpa ducimus, quo quam officia omnis?</p>
<p class="mostra">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Temporibus repudiandae perferendis adipisci, reprehenderit ipsam, accusantium ea nulla consequatur, quam exercitationem cumque explicabo! Officiis consectetur culpa ducimus, quo quam officia omnis?</p>
<p class="mostra">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Temporibus repudiandae perferendis adipisci, reprehenderit ipsam, accusantium ea nulla consequatur, quam exercitationem cumque explicabo! Officiis consectetur culpa ducimus, quo quam officia omnis?</p>
The first element with the class
.mostrais notfirst-child, because it already has an element before it, thep.oculta. That is, the onlyfirst-childin this case is the<p class="oculta">.– Sam
But wouldn’t that be the first class? p:first-Child would be no different from . shows:first-Child?
– Otavio Fagundes
Know some way to get the first occurrence of a certain class only with css?
– Otavio Fagundes
First class has nothing to do with first child. The
first-childtakes the first child of something. The first.mostrais not the first child of any element.– Sam
Dude, with CSS I don’t know how it does it.
– Sam
@hugocsl has a way of doing it there?
– Sam
@Sam the way he asked it ends up being duplicated anyway, but this questioning in the comment changes things a little... I’m even testing here, but I believe the easiest way would be to include an extra class in the first type element
mostrat n1, but I’m still testing.– hugocsl
Otavio the way you ask leaves the question as duplicate, but I urge you to edit and ask as something like "Select the first occurrence of the class" or something like, then I remove the duplicate ok
– hugocsl
All right, I edited ^_^
– Otavio Fagundes