Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari and background-clip: text not working well on multiple lines of display:inline text element

Tags:

html

css

safari

I don't know why, but when I set

background-clip: text

to clip a gradient/image/whatever with text (display: inline), only Safari doesn't work as it is supposed to.

I recreated a pen with this issue: https://codepen.io/steexd/details/qBZVbWY

Test it with Firefox or Chrome and then with Safari: you will notice that multi-line text won't clip correctly the background gradient.

Expected result:

Firefox

Safari:

Safari

Any help would be really appreciated :)

like image 333
Stefano Avatar asked Sep 03 '20 16:09

Stefano


People also ask

What is webkit background-clip?

The “background-clip: text” is supported in all main browsers with the Webkit prefix, it allows a background image to be clipped by a text element. In this guide we will look at examples using the background-clip property and the different values you can use.

What is background clipping?

The background-clip property defines how far the background (color or image) should extend within an element.

What does background-clip do in CSS?

The background-clip CSS property sets whether an element's background extends underneath its border box, padding box, or content box.


1 Answers

You can add -webkit-box-decoration-break: clone;

It will make the text legible, however it isn't exactly what you're asking for as it will repeat the gradient on each line.

box-decoration-break property on MDN

h1 {
  max-width:120px;
}
span {
  background-image: -webkit-linear-gradient(right, red, pink);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  -webkit-box-decoration-break: clone; 
}
<div>
   <h1>Hi, i'm a text with a <span>long span gradient</span>.</h1>
</div>
like image 76
aks. Avatar answered Oct 13 '22 19:10

aks.