drhirn drhirn - 2 months ago 7
CSS Question

Hide "non-element" using css

Following code:

<li>
<a href="...">bla</a>
<span>blabla</span>
hidethistext
</li>


How could I hide the "non-element" "hidethistext" with
display:none
using CSS without affecting everything else? Meaning, what would be the right selector?
Tried using
:not(..)
but that seemed not the right approach.

Answer

You can't. With css you can only select elements. The :not selector is used to select an element that is not of class x, does not have id y or is not element z. But hidethistext is just a textnode, which cannot be selected. The only solution is to wrap it in a <span/> element with another class then the first span