简体   繁体   English

IE9中的css3 text-shadow

[英]css3 text-shadow in IE9

Is there an easy way to have css3 text-shadow 's working in IE9? 是否有一种简单的方法让css3 text-shadow在IE9中运行? At least a single text shadow would be great. 至少一个文本阴影会很棒。 I guess ideally IE8 is supported as well. 我想理想情况下也支持IE8。 I'm hoping there's a simple jquery plugin or .htc file which just looks at text-shadow css property of an element and implements it for IE9. 我希望有一个简单的jquery插件或.htc文件,它只是查看元素的text-shadow css属性并为IE9实现它。

Yes, but not how you would imagine. 是的,但不是你想象的那样。 According to caniuse (a very good resource) there is no support and no polyfill available for adding text-shadow support to IE9. 根据caniuse (非常好的资源),没有支持,也没有可用于向IE9添加text-shadow支持的polyfill。 However, IE has their own proprietary text shadow ( detailed here ). 但是, IE有自己的专有文本阴影( 详见此处 )。

Example implementation, taken from their website (works in IE5.5 through IE9): 示例实现,取自他们的网站(在IE5.5到IE9中工作):

p.shadow { 
    filter: progid:DXImageTransform.Microsoft.Shadow(color=#0000FF,direction=45);
}

For cross-browser compatibility and future-proofing of code, remember to also use the CSS3 standard text-shadow property ( detailed here ). 对于跨浏览器兼容性和面向未来的代码,请记住还要使用CSS3标准的text-shadow属性( 在此处详述 )。 This is especially important considering that IE10 has officially announced their intent to drop support for legacy dx filters . 考虑到IE10已经正式宣布放弃对传统dx过滤器的支持,这一点尤为重要。 Going forward, IE10+ will only support the CSS3 standard text-shadow . 展望未来,IE10 +仅支持CSS3标准text-shadow

As IE9 does not support CSS3 text-shadow , I would just use the filter property for IE instead. 由于IE9不支持CSS3 text-shadow ,我只会使用IE的filter属性。 Live example: http://jsfiddle.net/dmM2S/ 实例: http//jsfiddle.net/dmM2S/

text-shadow:1px 1px 1px red; /* CSS3 */

can be replaced with 可以替换为

filter: Shadow(Color=red, Direction=130, Strength=1); /* IE Proprietary Filter*/

You can get the results to be very similar. 你可以得到非常相似的结果。

Try CSS Generator . 试试CSS Generator

You can choose values and see the results online. 您可以选择值并在线查看结果。 Then you get the code in the clipboard. 然后你得到剪贴板中的代码。
This is one example of generated code: 这是生成代码的一个示例:

text-shadow: 1px 1px 2px #a8aaad;
filter: dropshadow(color=#a8aaad, offx=1, offy=1);

I was looking for a cross-browser text-stroke solution that works when overlaid on background images. 我正在寻找一种跨浏览器的文本笔划解决方案,当覆盖在背景图像上时可以正常工作。 think I have a solution for this that doesn't involve extra mark-up, js and works in IE7-9 (I haven't tested 6), and doesn't cause aliasing problems. 我认为我有一个解决方案,不涉及额外的标记,js和IE7-9中的工作(我没有测试过6),并且不会导致别名问题。

This is a combination of using CSS3 text-shadow, which has good support except IE ( http://caniuse.com/#search=text-shadow ), then using a combination of filters for IE. 这是使用CSS3 text-shadow的组合,除了IE( http://caniuse.com/#search=text-shadow )之外,它有很好的支持,然后使用IE的过滤器组合。 CSS3 text-stroke support is poor at the moment. CSS3文本笔划支持目前很差。

IE Filters IE过滤器

The glow filter ( http://www.impressivewebs.com/css3-text-shadow-ie/ ) looks terrible, so I didn't use that. 发光滤镜( http://www.impressivewebs.com/css3-text-shadow-ie/ )看起来很糟糕,所以我没有使用它。

David Hewitt's answer involved adding dropshadow filters in a combination of directions. David Hewitt的答案涉及在方向组合中添加阴影滤镜。 ClearType is then removed unfortunately so we end up with badly aliased text. 然后遗憾地删除了ClearType,因此我们最终得到了错误的别名文本。

I then combined some of the elements suggested on useragentman with the dropshadow filters. 然后我将useragentman上建议的一些元素与dropshadow过滤器结合起来。

Putting it together 把它放在一起

This example would be black text with a white stroke. 此示例为带有白色笔划的黑色文本。 I'm using conditional html classes by the way to target IE ( http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ ). 我正在使用条件html类来定位IE( http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ )。

#myelement {
    color: #000000;
    text-shadow:
    -1px -1px 0 #ffffff,  
    1px -1px 0 #ffffff,
    -1px 1px 0 #ffffff,
    1px 1px 0 #ffffff;
}

html.ie7 #myelement,
html.ie8 #myelement,
html.ie9 #myelement {
    background-color: white;
    filter: progid:DXImageTransform.Microsoft.Chroma(color='white') progid:DXImageTransform.Microsoft.Alpha(opacity=100) progid:DXImageTransform.Microsoft.dropshadow(color=#ffffff,offX=1,offY=1) progid:DXImageTransform.Microsoft.dropshadow(color=#ffffff,offX=-1,offY=1) progid:DXImageTransform.Microsoft.dropshadow(color=#ffffff,offX=1,offY=-1) progid:DXImageTransform.Microsoft.dropshadow(color=#ffffff,offX=-1,offY=-1);
    zoom: 1;
}

I tried out the filters referenced above and strongly disliked the effect it created. 我尝试了上面引用的过滤器,并强烈反对它创建的效果。 I also didn't want to use any plugins since they'd slow down loading time for what seems like such a basic effect. 我也不想使用任何插件,因为它们会减慢加载时间,看起来像这样的基本效果。

In my case I was looking for a text shadow with a 0px blur, which means the shadow is an exact replica of the text but just offset and behind. 在我的情况下,我正在寻找具有0px模糊的文本阴影,这意味着阴影是文本的精确复制品,但只是偏移和后面。 This effect can be easily recreated with jquery. 使用jquery可以轻松地重新创建此效果。

<script>
    var shadowText = $(".ie9 .normalText").html();  
    $(".ie9 .normalText").before('<div class="shadow">' + shadowText + '</div>');
</script>
<style>
    .ie9 .shadow { position: relative; top: 2px; left: -3px; }
</style>

This will create an identical effect to the css3 text-shadow below. 这将创建与下面的css3文本阴影相同的效果。

    text-shadow: -3px 2px 0px rgba(0, 0, 0, 1.0);

here's a working example (see the large white text over the main banner image) http://www.cb.restaurantconnectinc.com/ 这是一个有效的例子(见主横幅图片上的大白文) http://www.cb.restaurantconnectinc.com/

The answer of crdunst is pretty neat and the best looking answer I've found but there's no explanation on how to use and the code is bigger than needed. crdunst的答案非常简洁,我找到了最好看的答案,但没有解释如何使用,代码比需要的大。

The only code you need: 您需要的唯一代码:

#element {
    background-color: #cacbcf;
    text-shadow: 2px 2px 4px rgba(0,0,0, 0.5);
    filter: chroma(color=#cacbcf) progid:DXImageTransform.Microsoft.dropshadow(color=#60000000, offX=2, offY=2);
}

First you MUST specify a background-color - if your element should be transparent just copy the background-color of the parent or let it inherit. 首先你必须指定一个background-color - 如果你的元素应该是透明的,只需复制父颜色的背景颜色或让它继承。 The color at the chroma-filter must match the background-color to fix those artifacts around the text (but here you must copy the color, you can't write inherit ). 色度过滤器的颜色必须与背景颜色匹配,以修复文本周围的这些伪影(但是在这里你必须复制颜色,你不能写inherit )。 Note that I haven't shortened the dropshadow-filter - it works but the shadows are then cut to the element dimensions (noticeable with big shadows; try to set the offsets to atleast 4). 请注意,我没有缩短投影过滤器 - 它可以工作,但阴影会被切割为元素尺寸(大阴影会很明显;尝试将偏移设置为至少4)。

TIP: If you want to use colors with transparency (alpha-channel) write in a #AARRGGBB notation , where AA stands for a hexadezimal value of the opacity - from 01 to FE, because FF and ironically also 00 means no transparency and is therefore useless.. ^^ Just go a little lower than in the rgba notation because the shadows aren't soft and the same alpha value would appear darker then. 提示:如果要使用透明度(alpha通道)的颜色写入#AARRGGBB表示法 ,其中AA代表不透明度的十六进制值 - 从01到FE,因为FF和具有讽刺意味的是00也表示没有透明度,因此没用.. ^^只是比rgba表示法低一点,因为阴影不柔和,相同的alpha值会显得更暗。 ;) ;)

A nice snippet to convert the alpha value for IE (JavaScript, just paste into the console): 一个很好的代码片段来转换IE的alpha值(JavaScript,只需粘贴到控制台):

var number = 0.5; //alpha value from the rgba() notation
("0"+(Math.round(0.75 * number * 255).toString(16))).slice(-2);

ISSUES: The text/font behaves like an image after the shadow is applied; 问题:文本/字体在应用阴影后的行为类似于图像; it gets pixelated and blurry after you zoom in... But that's IE's issue, not mine. 放大后它会变得像素化和模糊......但这是IE的问题,而不是我的问题。

Live demo of the shadow here: http://jsfiddle.net/12khvfru/2/ 这里的影子现场演示: http//jsfiddle.net/12khvfru/2/

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

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