简体   繁体   English

Safari 和背景剪辑:文本在多行显示中无法正常工作:内联文本元素

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

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.要剪辑渐变/图像/任何带有文本的内容(显示:内联),只有 Safari 无法正常工作。

I recreated a pen with this issue: https://codepen.io/steexd/details/qBZVbWY我用这个问题重新创建了一支笔: 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.使用 Firefox 或 Chrome 然后使用 Safari 对其进行测试:您会注意到多行文本无法正确剪切背景渐变。

Expected result:预期结果:

火狐

Safari:苹果浏览器:

苹果浏览器

Any help would be really appreciated :)任何帮助将非常感激 :)

You can add -webkit-box-decoration-break: clone;您可以添加-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 MDN 上的 box-decoration-break 属性

 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM