search

Home  >  Q&A  >  body text

Title rewritten to: CSS > Select first element in tree

<p>I've been trying to select only the first blockquote in the body of the email, which goes something like this: </p> <pre class="brush:php;toolbar:false;"><div class="myclass"> <br><p></p> <div><div> <!--sometimes less, sometimes more divs--> <blockquote> <!--The blockquote I want to select--> <div> <div> <br> <blockquote> <Wait...> </blockquote> </div> </div> </blockquote> </div></div> </div></pre> <p>The problem is, the formatting may vary from email to email, and there may be one or more divs before the first blockquote,</p><p> So use: </p> <pre class="brush:php;toolbar:false;">.myclass > div > div > blockquote {}</pre> <p>Not always valid,</p><p> This: </p> <pre class="brush:php;toolbar:false;">.myclass blockquote:first-of-type {}</pre> <p>Each blockquote will be selected</p> <p>So I only want to select the first blockquote regardless of its position on the html tree. </p>
P粉237125700P粉237125700458 days ago499

reply all(1)I'll reply

  • P粉949190972

    P粉9491909722023-09-01 17:49:20

    Like this? Selects the first nested blockquote of the container .myclass, but does not select any blockquote## that is a child of the first blockquote #.

    .myclass blockquote:not(blockquote blockquote) {
      background-color: red;
    }
    <div class="myclass">
      <br>
      <p></p>
      <div>
        <div>
          <!--有时少有时多的div-->
          <blockquote>
            <!--我想选择的blockquote-->
            <div>
              <div> <br>
                <blockquote>
                </blockquote>
              </div>
            </div>
          </blockquote>
        </div>
      </div>
    </div>

    reply
    0
  • Cancelreply