0

https://codepen.io/bazzle/pen/jyWdjM

I want to select the first p but not the p nested inside blockquote, or any other element.

In other words the first p out of all the child p's but not grandchild p's

<div class="article__body">
  <p>
    It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
</p>
<blockquote>
  <p>
    It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
  </p>
</blockquote>
<p>
    It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
</p>
</div>

CSS (less)

.article__body{
        p:first-of-type{
            background-color:green;
        }
}
bazzlebrush
  • 428
  • 2
  • 15

2 Answers2

0

Maybe you should try this:

.article_body p:nth-of-type(1){
    background-color:green;
}

or just create a class HTLM: <p class="yourclass"></p>

CSS: .yourclass{background-color:green;}

Damon
  • 127
  • 1
  • 2
  • 15
0

I try

.article__body p:nth-of-type(1){
            background-color:green;
        }
Junior
  • 77
  • 9