在 CSS2 标准中更改图像悬停的 alpha 值?
我正在尝试为我的图像添加 Alpha 效果。 图像是圆角矩形。 我知道 CSS3 中有可以更改 alpha 的属性,但我正在尝试遵守 w3c 标准,该标准仍然是 CSS2。
抱歉,我没有提前正确地陈述我的问题。 当我将鼠标悬停在使用 CSS2 的图像上时,我试图更改 alpha。 我正在考虑使用“背景图像”作为 100% alpha,并使用 img 标签作为 50% alpha。 有没有更好的方法来做到这一点?
i'm trying to add alpha effect for my image. the image is in rounded corner rectangular shape. i know there is attributes to change the alpha in CSS3, but i'm trying to be compliant with the w3c standard, which is still CSS2.
Sorry i didn't state my question correctly ealier. i was trying to change the alpha when i hover over the image using CSS2. i'm thinking to use the "background-image" for 100% alpha, and use the img tag for the 50% alpha. is there any better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果图像是 PNG,则可以直接在图像中包含 Alpha。 当然,这需要 IE6 的 PNG Fix 脚本。
否则,您可以使用 CSS 设置透明度。
编辑:更新为仅在悬停时起作用,请注意,这在 IE6 中不起作用。
If the image is a PNG, you can include alpha directly in the image. Of course this would require the PNG Fix script for IE6.
Otherwise, you can use CSS to set the transparency.
Edit: Updated to only work on hover, note that this won't work in IE6.
Web 开发人员实现透明效果的典型方法是使用部分透明的 PNG 文件作为背景。
使用 png 将按您的预期工作,但不透明度不会按预期工作:
这将使 DIV 50% 透明,包括其所有子项、文本等。 您确实需要调整不透明度设置,以确保获得预期的结果。
The typical way a web developer implements the transparent effects is using a partially transparent PNG file as a background.
Using the png will work as you would expect, however opacity doesn't work as expected:
This will make DIV 50% transparent, including all of its children, text and all. You will really need to play around with the opacity settings to make sure you get results as you would expect.
如果您可以忍受 IE6 稍差的用户体验,一个更简单的修复方法是为所有现代浏览器使用 alpha 透明图像,并将不透明(或仅一种颜色)的图像发送到 IE6。 对于那些少数用户来说,看起来有点糟糕,但需要维护的代码要少得多。
An even simpler fix, if you can stand a slightly worse user experience for IE6, is to use an alpha-transparent image for all modern browsers, and send an image with no transparency (or just one-color) to IE6. Looks a little worse for those few users, but is a lot less code to maintain.