2

I would like to use a CSS selector to select a specific child TAG but only if parent has no other children or text.

In this specific case the <a> tag that needs to be selected is wrapped in a <p> tag.

I'm looking for a CSS-only solution (I'm curious to know if it's actually possible)

<p><a>This is selected</a></p> // selected
<p><a>This is NOT selected</a><span>other children</span></p> // NOT selected
<p><a>This is NOT selected</a>Other text</p> // NOT selected
juniorDEV
  • 21
  • 4
  • 1
    @Austin - I got burnt by that yesterday as well. Seems like maybe there's some new code that tries to collapse edits close in time and that it is a bit... overzealous. – Alexander Nied May 06 '22 at 15:47
  • Is it possible that your question is a duplicate of [CSS no sibling selector](https://stackoverflow.com/questions/7866784/css-no-sibling-selector)? If not, can you clarify how your question differs from the one at that link? – Alexander Nied May 06 '22 at 15:48
  • The missing part of [CSS no sibling selector](https://stackoverflow.com/questions/7866784/css-no-sibling-selector) is that the Tag is Not selected also if it has other content that a sibling (for instance a simple text) `

    This is NOT selectedOther text

    // NOT selected`
    – juniorDEV May 06 '22 at 15:54
  • Thanks for explaining-- I have retracted my close vote. – Alexander Nied May 06 '22 at 18:06

0 Answers0