1

Let's suppose I have the following text strings within a CSS class:

Text:

(2) 91-180
2, 91-180

Class:

<text class="nv-legend-text">(2) 91-180</text>

Is there, by any chance, a way how to hide the (2) or 2, using CSS so only the text 91-180 is shown?

I have no other way how can I control/adjust the code itself, only custom CSS.

3
  • can't you just wrap (2) inside a span assign the said span with a class and give it a property of display: none;? Commented Feb 2, 2022 at 8:42
  • Without changing the HTML structure, there is no way for CSS to use logic and "find" or "grab" something and remove/hide it. CSS can only apply styles to elements that have a selector like tag, class, id etc. Commented Feb 2, 2022 at 8:50
  • I don't their is any way to make css see the text differently without changing html or adding some js. You CAN increase the text indent a bit more. But that wont work if the text to be hidden isn't at start or if it's longer/shorter then a specific number... Commented Feb 2, 2022 at 9:08

2 Answers 2

3

Use text-indent but you will need a specific value based on the font metrics:

text {
  display: inline-block;
  text-indent: -18px;
  overflow: hidden;
}
<text class="nv-legend-text">(2) 91-180</text>

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

1 Comment

yeah, with only custom css this looks like the best (if not only) option out there
0

You can wrap the text you want to hide and either use display: none; to make it disappear. Or color: transparent; to make the text transparent. See the snippet below for your reference:

.ex1{
  display: none;
}
.ex2{
  color: transparent;
}
<p><span class="ex1">(2)</span>018231</p>
<p><span class="ex2">(2)</span>018231</p>

4 Comments

if they can wrap the text, why not simply removing it? from the question: only custom CSS.
So they may manipulate it still with js if they want to? There's a difference with it not being in the DOM at all, and then just for it to be hidden temporarily, no?
that's not the question. I don't see any DOM manipulation requirement or JS involved in the question
I'm just answering your question of why not simply removing it?

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.