CSS3 是否支持对单个
的背景使用图像和渐变?

发布于 2024-09-28 21:43:07 字数 224 浏览 1 评论 0原文

我知道您可以在 CSS3 中的单个

上制作多个背景,但是是否可以混合图像引用背景(即 url(...) )带有渐变生成背景(例如-moz-linear-gradient(...))?

如果是这样,语法是什么?

如果不是,达到相同结果的最佳实践是什么?

谢谢。

I know you can do multiple backgrounds on a single <div> in CSS3, but is it possible to mix an image-referencing background (i.e. url(...)) with a gradient generating background (e.g. -moz-linear-gradient(...))?

If so, what is the syntax?

If not, what is a best-practice to achieve the same result?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

徒留西风 2024-10-05 21:43:07

你可以!

background: -moz-linear-gradient(-45deg, rgba(0,0,255,0), rgba(0,0,255,1)), url("image");

可以在 http://software.hixie.ch 观看直播/utilities/js/live-dom-viewer/saved/675

当然,请注意,CSS 渐变仍在不断变化。

You can!

background: -moz-linear-gradient(-45deg, rgba(0,0,255,0), rgba(0,0,255,1)), url("image");

which can be seen live at http://software.hixie.ch/utilities/js/live-dom-viewer/saved/675.

Note, of course, that CSS gradients are still in flux.

无力看清 2024-10-05 21:43:07

我假设您正在尝试有条件地使用支持的渐变,但否则图像?

如果是这样,那么一种方法是通过 Javascript 来完成——例如:

document.getElementById("whatever").style = "url(...)";

我不确定如何检查浏览器类型,但这应该是一个简单的 Google 搜索。


但是,如果您尝试使图像叠加在渐变上,但透明(以便部分渐变显示出来),您可以尝试此处描述的内容: http://www.css3.info/introduction-opacity-rgba/

请注意,它使用 0.0-1.0 作为 alpha,而不是0-255。

I assume you are trying to conditionally use gradients where supported, but image otherwise?

If so, then one way would be to do it via Javascript -- for example:

document.getElementById("whatever").style = "url(...)";

I'm not sure exactly how to check for the browser type, but that should be a simple Google search.


However, if you are trying to make it so that the image is superimposed on the gradient, but transparent (so that some of the gradient is showing through), you could try what is described here: http://www.css3.info/introduction-opacity-rgba/

Note that it uses 0.0-1.0 for alpha, not 0-255.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文