简体   繁体   English

使用CSS在图像上应用图像蒙版

[英]Apply image mask over text using CSS

I wish to mask some anchor text of size 4.5em with a repeating image, so that the image would only show over the region where text is present. 我希望用重复的图像掩盖一些尺寸为4.5em的锚文本,这样图像只会显示文本所在的区域。 Is there any way that I can do this with CSS? 有什么办法可以用CSS做到这一点吗? Please help with relevant code and example, if possible. 如果可能,请帮助相关代码和示例。 Thanks. 谢谢。 :) :)

Not sure why you got the down vote, seems like a legit question to me. 不知道为什么你得到了投票,对我来说似乎是一个合法的问题。 Could've been a bit more descriptive though. 虽然可能有点描述性。

Anyway, I think you're not out of luck! 无论如何,我认为你不是运气不好! The only fathomable way to do this in CSS is using the image-mask property. 在CSS中唯一能做到这一点的方法是使用image-mask属性。 It's really easy, but it has pretty poor browser support at the moment. 这很简单,但目前浏览器支持很差。 think it works well in firefox, opera and google chrome. 认为它在firefox,opera和google chrome中运行良好。 No IE support at the moment. 目前没有IE支持。 Here's how it's used: 以下是它的使用方法:

p{
    -webkit-mask-image: url(/path/to/mask.png);
    -o-mask-image: url(/path/to/mask.png);
    -moz-mask-image: url(/path/to/mask.png);
    mask-image: url(/path/to/mask.png);
}

That will mask every paragraph with the image path. 这将使用图像路径掩盖每个段落。 Fortunately, it degrades nicely in IE, so users won't even notice anything wrong it'll show up as normal text! 幸运的是,它在IE中很好地降级,因此用户甚至不会注意到任何错误,它将显示为普通文本! so if you don't REALLY need IE support, do this. 因此,如果您真的不需要IE支持,请执行此操作。 If you do need IE support: 如果您确实需要IE支持:

Use an image. 使用图像。 Make it in photoshop. 在photoshop中制作它。 :( :(

Here's a demo of how its used: 这是一个如何使用它的演示:

http://trentwalton.com/2011/05/19/mask-image-text/ http://trentwalton.com/2011/05/19/mask-image-text/

他们不喜欢WebKit外面的mask-image属性,但目前你可以通过IE中的“过滤器”Firefox中的SVG/ Opera?/ WebKit?/ IE? )来模拟它

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

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