It's 2022 and :only-child isn't aware of text nodes?

I'm trying to select an image that is the only direct descender of an element, with no text node siblings, e.g.:




div img:only-child will select this img in both cases, as will div img:first-child and div img:last-child

Am I missing something?


@omgmog I never stumble on a case like this, probably because I have a compulsion not to leave a text node untagged. In your second example I would have had:


And, off-topic: do we have markdown in Mastodon? I had to refrain from wrapping the above code within ``

@m2m I think not. I've also been resisting the compulsion to wrap `code` with backticks! 😅

@m2m Yeah I was hoping to avoid needing to use extra markup. It's frustrating because the Javascript DOM knows about TextNodes, but CSS is like "🤷🤷🤷"

@omgmog maybe this:

though it's experimental and lack widespread support. Also, I'm not entirely sure it's what you're looking for.

@m2m haha thanks for looking! I will just have to resolve to not being able to do what I wanted

Sign in to participate in the conversation

INDIEWEB.SOCIAL is an instance focused on the #Openeb, #Indieweb, #Fediverse, #Mastodon #Selfsovereign #identity (#SSI), #Humanetech and #Calm technologies evolution.