Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent text with text-shadow in IE

When using color: rgba(255,255,255,0.0); in conjunction with text-shadow: 0px 0px 2px rgba(255,255,255,1);, Internet Explorer seems to inherit the transparency of the text-shadow from the text itself, causing the shadow not to appear at all.

JSFiddle example (view in IE): http://jsfiddle.net/495dZ/1/

Is there a clever pseudo-class technique to work around this? Or maybe something using jQuery to achieve a similar effect?

like image 212
elli mccale Avatar asked Dec 09 '13 23:12

elli mccale


Video Answer


2 Answers

You could just hide the text off the edge of the window/screen, consider adding a fallback for older versions of IE as well.

Working Example

.black-box {
    background: url(http://i44.tinypic.com/2rzwis3.jpg) no-repeat;
    padding: 20px;
}
span.shadow {
    font: 20px Arial;
    position: absolute;
    left:-100px;
    top:-100px;
    color: rgba(0, 0, 0, 1);
    text-shadow: 120px 120px 2px rgba(255, 255, 255, 1);
}

<!--[if lte IE 9]>
    <style>
    span.shadow {
        position: static;
        display:inline-block;
        font: 20px Arial;
        color: rgba(255, 255, 255, 1);
        filter:progid:DXImageTransform.Microsoft.Blur(pixelradius=2.25);
        }
    </style>
<![endif]-->

<div class="black-box"> 
    <span class="shadow">This is some text.</span>
</div>
like image 85
apaul Avatar answered Oct 03 '22 20:10

apaul


A extra text-shadow definition for IE 10+ do the trick:

.transparent-text-with-shadow {

    color:         transparent;                            // or rgba(0,0,0,0);
    text-shadow:   rgba(0,0,0,1) 0px 0px 10px;             // for Chrome etc.
    text-shadow:   rgba(0,0,0,1) 0px 0px 10px 0.01em;      // for IE 10+
}

The second text-shadow definition overwrites the first in IE 10+ only, because IE 10+ supports a fourth length value for the shadow's "spread" - see http://caniuse.com/#search=text-shadow

In other browsers, like Chrome, the second text-shadow definition overwrite fails, because they do not support a fourth length value for the shadow, and so they will use the first text-shadow definition.

(Make sure the fourth "spread" value is very small - so you can't see any rendering differences.)

like image 42
LosMikEos Avatar answered Oct 03 '22 19:10

LosMikEos