0

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.

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Seems you're right. Unfortunately, I'm not the one who produces the code, this is done by an application. I'm just here to make it look good ;). So I can't wrap it into a span.
Or call the guy and ask him if he wants to wrap it in a span :p You can also use javascript to do it dynamically. Although that's a suboptimal solution...
I'll file a bug at phabricator.wikimedia.org ;). Actually thought about javascript too. Suboptimal, as you say, but may be worth a try.
1

You can use the visibility property since it can be overridden.

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

CSS

/* hide all elements (including textnode "hidethistext" */
li {
  visibility: hidden;
}

/* set other elements to visible */
li span, li a {
  visibility: visible;
}

Example here on this jsfiddle.

Related SO question.

2 Comments

Still the browser reserves space for the text. That's what I'm trying to prevent.
@drhirn in that case you'll need to set it's display to none. You'll have to put it into a separate <span> tag to accomodate for that. Look at @giorgio's answer if that's the functionality you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.