Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 711
Logan Garcia Avatar asked Jul 07 '17 06:07

Logan Garcia


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-clip content box?

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

What is background-clip for?

background-clip lets you control how far a background image or color extends beyond an element's padding or content.

How do you put a background on text in CSS?

Use text inside :after pseudo element to make appear text as the background. Output: Using :before pseudo elements: Using :before pseudo elements with :before pseudo elements having lower z-index value make it to appear as background. Use text inside :before pseudo element to make appear text as the background.


1 Answers

Found this fix. Add this to the element that has the properties that create gradient text:

-webkit-box-decoration-break: clone;
like image 144
Chevas Balloun Avatar answered Sep 22 '22 05:09

Chevas Balloun