0

My question is similar to this one, except the structure of my file is:

<div>
    <p><span class="ignore">blah</span></p>
    <p>blih</p>
    <p>blouh</p>
</div>

I want to have a CSS selector on blih. If the span tag is absent, the selector should apply to blah instead.

I can't use div > p:not(.ignore):first-child since the ignore class applies to the span tag, not the p tag. I can't apply the ignore class to the p tag, since this is generated from Markdown.

Is there a CSS selector that does the job, and avoids having to add a span tag to blih?

Ted
  • 788
  • 1
  • 8
  • 17
  • 1
    you cannot, the duplicate isn't trivial but basically you need to *not* select the p that contain that span (you need a parent selector for this) ... if you are able to select that p then you will face another difficulty which is nth-child doesn't exclude elements (explained in the question you linked) – Temani Afif Feb 19 '19 at 22:04
  • Hmmm I'm not sure I understand why the question is a duplicate, but I understand why what I'm asking for is impossible. Thanks! – Ted Feb 19 '19 at 22:08
  • like I explained, the missing part of your *puzzle* is a parent selector. If you have it then you can do what you want. And the duplicate explain that a parent selector is still not possible --> so your whole thing is impossible (thus the duplicate) – Temani Afif Feb 19 '19 at 22:10

0 Answers0