mastodon.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
The original server operated by the Mastodon gGmbH non-profit

Administered by:

Server stats:

354K
active users

Ana Tudor 🐯

Want inline semitransparent text background with no overlap?

Here's how on @codepen
codepen.io/thebabydino/pen/gbO
(you can see the overlap problem and the desired result below)

The `filter` combines 2 `feColorMatrix` techniques:

1️⃣ using a channel as an alpha mask

2️⃣ solid fill

#CSS#SVG#filter

1⃣ using a channel as an alpha mask - the bottom row lets us choose which input channel is used for the output alpha; if we set one of the RGB channels (first 3 values) to 1 and zero all else on the last row, that channel is used as the alpha mask.

Here is the interactive demo illustrating this on @codepen
codepen.io/thebabydino/full/OJ

#CSS#SVG#filter

2️⃣ solid fill - first three values on the last column are set to the desired RGB values (decimal representation of percentage RGB)

Interactive demo on @codepen
codepen.io/thebabydino/full/LY

mastodon.social/@anatudor/1121

#SVG#filter#css

@patrick_h_lauke Wait, that's a slightly different problem and doesn't even require an SVG filter (like the semi-transparency overlap does). Here's a fork codepen.io/thebabydino/pen/ogN

codepen.ioSetting background to always be in the back...

@anatudor blend mode works in that case against white page background, but it's not quite a general approach for varying page backgrounds etc. just after some way of "merging" all backgrounds together as one unit there that sits behind all the text (and can then be opaque, or transparent, or whatever really). but yeah, can hack it for very specific controlled uses, sure...

@patrick_h_lauke You don't need a white page background. Refresh to see. In general, it works for any text that's super close to either white or black, regardless of the page backdrop. And with the SVG filter method I'm using in my transparency overlap demo, it can be made to work for any text/ highlight combo, like blue text + yellow highlight.

@anatudor Probably worth a comment somewhere that your demo forces pure white text on a black background color, since you're setting color in the filter & using input color to distinguish text vs background.

I'd instead use feComponentTransfer on the alpha channel to normalize the semi-transparent background sections while preserving the opaque text regardless of color:

codepen.io/AmeliaBR/pen/XJWjEm

Only a little annoying because of the component transfer syntax (explained in the pen description).

@anatudor Aside: It's been a while since I've played with SVG filters, and the definitions in the spec (drafts.fxtf.org/filter-effects) were making my head spin.

Then I remembered, I wrote a whole book on SVG with a chapter on filters, I'll go look up what I said! Except, I didn't actually discuss feComponentTransfer in the book (😭).

But, my SVG elements & attributes reference page was enough to help jog my memory: oreillymedia.github.io/Using_S

I used `table` not `discrete` to avoid harsh pixel aliasing.

@AmeliaBR But not regardless of alpha. It still shows overlap if alpha is .75 and it breaks the text edges for an alpha of .25 :(

@anatudor Yeah, that's the annoying bit with the syntax. You need to adjust the number of repeats in the `tableValues` attribute to make sure it can cover closer-to-opaque levels.

I hadn't realized that less opaque backgrounds would result in more damage to the text anti-aliasing. But you could make *fewer* repeats in the table function for that.

Since the SVG code is being generated by a pre-processor anyway, I guess you could come up with a function for that? But it's definitely not optimal.

@anatudor @codepen

Here is a fix to poor text selection color with the filter trick:

```css
/* inner span helps fix background-letter overlap */
span { isolation: isolate; }

::selection {
background: ;
color: ;
}
```