Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

background-clip: text #716

Open
thebabydino opened this issue Sep 18, 2024 · 5 comments
Open

background-clip: text #716

thebabydino opened this issue Sep 18, 2024 · 5 comments
Labels
focus-area-proposal Focus Area Proposal

Comments

@thebabydino
Copy link

Description

This is now supported unprefixed and in the shorthand in all browsers, but bugs still remain.

Most notable ones, both related to multiple background layers:

  • Firefox 🪲 1481498 - if one background-clip value is text, but not all of them are, the result is incorrect.
  • Safari 🪲 267129 - if we have at least one background layer clipped to text, this breaks background-blend-mode

The majority of my most common uses for background-clip: text involve blending two background layers out of which only one is clipped to text.

So I most commonly have to resort to an absolutely positioned pseudo-element covering its parent. The pseudo then gets blended with its parent's text content.

This can be problematic for inline elements like links. Let's say we want an on :hover/ :focus XOR effect created with the difference blend mode. All is fine if the link doesn't wrap.

Screenshot when the link doesn't wrap.
:hover case scenario

But if the link wraps, we have a problem.

Animated GIF. Shows how in the case of a multi-line link, the pseudo-element is just between the left of the first word in the link text and the last word in the same link text.
the problem with multi-line links

To get around this, I have to make the link inline-block. Which also breaks when the link is wider than is container. To also avoid that problem, I need to wrap the link text inside a span which I then blend with the actual link. Which works, but isn't ideal.

Specification

CSS Backgrounds and Borders Module Level 3

Additional Signals

No response

@gsnedders
Copy link
Member

@jsnkuhn
Copy link

jsnkuhn commented Sep 21, 2024

The new/experimental background-clip value of border-area included in some of these tests seems to make this less likely to get accepted.

@jsnkuhn
Copy link

jsnkuhn commented Sep 22, 2024

Metrics from Chrome Status:

background-clip is used on 37% of page loads. This is much higher than I expected.
https://chromestatus.com/metrics/css/timeline/popularity/23

-webkit-background-clip is around 8%
https://chromestatus.com/metrics/css/timeline/popularity/178

not sure if there's a way to get specific numbers for the text value

@progers
Copy link

progers commented Oct 29, 2024

The new/experimental background-clip value of border-area included in some of these tests seems to make this less likely to get accepted.

@jsnkuhn , can you help me understand this? I think this proposal is just about background-clip: text, and would exclude border-area (#881)?

@jsnkuhn
Copy link

jsnkuhn commented Oct 30, 2024

This is specifically regarding the the lack of existing tests for multiple background-clip values that don't include border-area.

This sort of case as mentioned in the Firefox bug from the OP:

background-image: linear-gradient(), linear-gradient();
background-clip: text, border-box

In this case one of the gradients would be being used as a "text fill" and the other as an actual background-image. There is, as far as i can tell, no test for this. But there exists a similar test for multiple backgrounds/clips that included border-area:

https://wpt.fyi/results/css/css-backgrounds/background-clip/clip-border-area-multiple-backgrounds.html?label=master&label=experimental&aligned&q=background-clip

So something similar without the border-area would probably need to be created to cover this?

A similar issue exists with a lack of tests for a background-image: none to add a separate background-clip values for an image and the background-color.

background-color: red;
background-image: linear-gradient(), none;
background-clip: text, border-box

Here again the gradient is applied as a text fill and the image value of none is needed to include a clipping value for the background-color

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus-area-proposal Focus Area Proposal
Projects
Status: No status
Development

No branches or pull requests

4 participants