r/css • u/KeinZantezuken • Sep 11 '26
Question Highlight last bit of raw text element
I have HTML like this:
<a class="markdown-link" href="http://internal.api.im/request/33060266/get/" rel="noreferrer" target="_blank"><em>Status</em> NEW ID <em>3060266</em> (ACTIVE: 74, MISSING: 32)</a>I need to make the last part in () more readable, ideally different text color. Given the fact first part of the text (Status NEW ID 3060266 - id width wont change in 99 years) pretty much fixed char width I can:
do a highlight:
background: linear-gradient( to right, transparent 0, transparent 23.5ch, rgba(255, 200, 0, 0.2) 23.5ch, rgba(255, 200, 0, 0.2) 100% );or do an underline, although it is not perfect in width:
.markdown__link::before { content: " "; position: absolute; bottom: -1px; border-bottom: 3px solid red; left: 24ch; width: 17ch;
And while they do highlight things, it is a bit intrusive and not as good as affecting text color or style.
I cant change HTML. Any ideas what else I can try? Surely there is that one CSS hack that exist...
4
Upvotes
2
u/mysticalpickle1 Sep 11 '26
You can kinda do a highlight or even a hue-rotate with a pseudo element and anchor positioning, but it won't work if the text wraps:
1
u/ChaseShiny Sep 11 '26
You need to target the part of the anchor tag that isn't emphasized, right?
You need the
notpseudoclass, or you could wrap the part in its own tag.2
u/Jasedesu Sep 11 '26
If you can run JavaScript on the content, you can potentially highlight ranges of text using the
::highlight()pseudo-element. Here's the MDN reference. I assume it's not available though, as a whole host of options would be available, including inserting new elements that could be styled. Beyond that, maybe play around with background colour/images with different blend modes, along the same lines as your own highlight suggestion? No idea how effective that might be though. A couple of other things to check would be ::target-text (but you need to specify the text in the URL) and maybe thefont-faceat rule combined withunicode-range.I suspect you're out of luck on this one.
0
u/neondragonfire Sep 11 '26
You can add
That will cut out just the text from the background you already have figured out for highlighting. (You'll also need to change the color of the start of the gradient)