Safari on iOS not displaying text when using background-clip and text-fill-color combined with some pseudo elements

时间秒杀一切 提交于 2019-12-10 13:13:05

问题


I'm having a hard time solving this mystery. I have created a "knockout text" effect and added a separator using :after to a h2. It looks great on everything I've tested it on except for Safari on iOS (10.3.2).

Link to fiddle with a broken and temporary fix.

h2.gradient {
    color: #013c65;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 2em;
    line-height: 1em;
    background: linear-gradient(1deg, #800909, #332222);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    -moz-background-clip: text;
    -moz-text-fill-color: transparent;
    -ms-background-clip: text;
    -ms-text-fill-color: transparent;
    background-clip: text;
    text-fill-color: transparent;
}
h2.gradient:after {
    content: '';
    position: relative;
    display: block;
    height: .12em;
    width: 2.5em;
    background-image: linear-gradient(1deg, #800909, #332222);
    top: .5em;
}

Looks like the problem seems to be with combining background-clip: text;, text-fill-color: transparent;, and with the pseudo element: display: block;.

I am able to absolute position and display inline-block the pseudo element. For the time being, I've wrapped the header in <div class="special-heading"> and added separator after the div.

Would there be a reason why iOS doesn't like this or has anyone else experienced similar problems? I've found that adding a zero-width space &#8203; magically makes it work.

I'm thinking this might be a bug, however, because I am able to get the original method working occasionally with the web inspector open on my Mac.

Thanks for your thoughts!


回答1:


I faced similar issue and found alternative solution in separate thread.

The idea is to change display property to inline: display: inline. Doesn't require "HTML hacks".

Although this fix might not fit your layout needs, that's the only solution that worked for me from CSS perspective.

Source




回答2:


There is a bug in the official safari bug tracker. Unfortunately it looks like nobody has looked into it for the last two years:

https://bugs.webkit.org/show_bug.cgi?id=169125



来源:https://stackoverflow.com/questions/44963978/safari-on-ios-not-displaying-text-when-using-background-clip-and-text-fill-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!