CSS背景图像不透明?

编程入门 行业动态 更新时间:2024-10-09 07:23:06
本文介绍了CSS背景图像不透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

相关于 CSS:半透明背景,而不是文字,但略有不同。

我想知道是否可以更改背景图片的alpha值,颜色。显然,我可以保存图像与不同的alpha值,但我想能够动态调整alpha。

I'd like to know if it's possible to change the alpha value of a background image, rather than just the colour. Obviously I can just save the image with different alpha values, but I'd like to be able to adjust the alpha dynamically.

到目前为止,我得到的最好的是:

So far the best I've got is:

<div style="position: relative;"> <div style="position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; background-image: url(...); opacity: 0.5;"></div> <div style="position: relative; z-index: 1;"> <!-- Rest of content here --> </div> </div>

它可以工作,但它体积庞大和丑陋,并且在更复杂的布局中混乱。 >

It works, but it's bulky and ugly, and messes things up in more complicated layouts.

推荐答案

如果背景不需要重复,你可以使用sprite技术不同的不透明度变成一个(彼此相邻),然后用 background-position 来移动它们。

If the background doesn't have to repeat, you can use the sprite technique (sliding-doors) where you put all the images with differing opacity into one (next to each other) and then just shift them around with background-position.

您可以多次声明相同的部分透明的背景图片,前提是您的目标浏览器支持多个背景(Firefox 3.6+,Safari 1.0+,Chrome 1.3+,Opera 10.5+,Internet Explorer 9+)。这些多个图片的不透明度应该相加,您定义的背景越多。

Or you could declare the same partially transparent background image more than once, if your target browser supports multiple backgrounds (Firefox 3.6+, Safari 1.0+, Chrome 1.3+, Opera 10.5+, Internet Explorer 9+). The opacity of those multiple images should add up, the more backgrounds you define.

更多推荐

CSS背景图像不透明?

本文发布于:2023-11-05 02:51:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559707.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不透明   图像   背景   CSS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!