您可以使用 CSS 或 JavaScript 创建渐变为不透明的渐变吗?
WebKit 引入了创建 CSS 渐变的功能。例如,使用以下代码:
-webkit-gradient(linear, left top, left bottom, from(#fff), to(#000));
但是,是否可以使用 CSS 实现不透明度渐变?我希望渐变一侧为单色,另一侧渐变至零不透明度。
跨浏览器兼容性并不重要;重要的是。我只需要它在 Google Chrome 中工作即可。
有没有办法使用 CSS 来做到这一点?如果没有,可以使用 JavaScript(而不是 jQuery)完成类似的事情吗?
感谢您的帮助。
WebKit has introduced the ability to create CSS gradients. For example, with the following code:
-webkit-gradient(linear, left top, left bottom, from(#fff), to(#000));
However, is it possible to have an opacity gradient using CSS? I want the gradient to be a single color on one side, and fade to zero opacity on the other.
Cross-browser compatibility isn't important; I just need it to work in Google Chrome.
Is there some way to do this using CSS? If not, can something similar be done using JavaScript (not jQuery)?
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的
,对于颜色,使用 rgba(x, y, z, o),其中 o 是不透明度
应该起作用,
例如
编辑:
对于最终值(不透明度)1 是不透明的,而 1 是不透明的。 0 为透明
Yes
for the colors, use rgba(x, y, z, o) where o is the opacity
should work
e.g.
Edit:
For the final value (opacity) 1 is opaque & 0 is transparent
是的,您应该使用
rgba(red, green, blue, alpha)
http://www.w3.org/TR/css3-color/#rgba-color,示例(在 jsFiddle):Yup,
rgba(red, green, blue, alpha)
is what you should use http://www.w3.org/TR/css3-color/#rgba-color, example (Try it out on jsFiddle):未经测试,但这应该可以工作(在 FF 中可以工作(使用不同的语法)-我不确定 safari/webkit 是否知道 rgba):
not tested, but this should work (in FF this works (with a different syntax) - i'm not sure if safari/webkit knows rgba):