简体   繁体   English

如何使css background-blend-mode与渐变一起使用?

[英]How to make css background-blend-mode work with gradients?

I have a page with multiple backgrounds: one with gradient and one with texture pattern. 我有一个具有多个背景的页面:一个带有渐变,一个带有纹理图案。 But background-blend-mode doesn't work. 但是,背景混合模式不起作用。 Chrome appears to show only gradient layer. Chrome似乎只显示渐变图层。 When I try to blend two background-images or background-image with solid background-color it works well. 当我尝试将两个背景图像或背景图像与纯背景色混合时,效果很好。 But not with gradient. 但不是渐变。 Is something wrong? 有什么事吗

body {
width: 100%;
height: 100%;
background: url('../images/noisy.png');
background-color: rgba(29, 84, 140, 1);
background: -webkit-radial-gradient(center, ellipse cover, rgba(36,138,166,1) 0%,rgba(21,112,145,1) 42%,rgba(5,58,103,1) 100%);
background: radial-gradient(ellipse at center, rgba(36,138,166,1) 0%,rgba(21,112,145,1) 42%,rgba(5,58,103,1) 100%);  
background-blend-mode: multiply;}

And my goal is something like that: 我的目标是这样的:
图片

It does work with gradients you just need to use multiple backgrounds. 它确实适用于只需要使用多个背景的渐变。

The problem with your current code is that you are only setting one background. 当前代码的问题是您只设置了一个背景。

First you set background to an image: 首先,您将background设置为图像:

background: url('../images/noisy.png');

Then you override the image and set background to a gradient: 然后覆盖图像并将background设置为渐变:

background: radial-gradient(ellipse at center, rgba(36,138,166,1) 0%,rgba(21,112,145,1) 42%,rgba(5,58,103,1) 100%);

To assign multiple backgrounds you need to comma seperate them: 要分配多个背景,您需要用逗号隔开:

background: background1, background2, ..., backgroundN;

Using your gradient: 使用您的渐变:

 body { width: 100%; height: 100%; background: url('http://i.stack.imgur.com/PEnJm.png'); background-color: rgba(29, 84, 140, 1); /* ^ fallbacks for crappy IE ^ */ background: url('http://i.stack.imgur.com/PEnJm.png'), -webkit-radial-gradient(center, ellipse cover, rgba(36,138,166,1) 0%,rgba(21,112,145,1) 42%,rgba(5,58,103,1) 100%); background: url('http://i.stack.imgur.com/PEnJm.png'), radial-gradient(ellipse at center, rgba(36,138,166,1) 0%,rgba(21,112,145,1) 42%,rgba(5,58,103,1) 100%); background-blend-mode: multiply; } 

A gradient similar to your image example: 与图片示例类似的渐变:

 body { width: 100%; height: 100%; background: url('http://i.stack.imgur.com/PEnJm.png'), -moz-linear-gradient(left, rgba(21,112,145,1) 0%, rgba(36,138,166,1) 100%); background: url('http://i.stack.imgur.com/PEnJm.png'), -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(21,112,145,1)), color-stop(100%,rgba(36,138,166,1))); background: url('http://i.stack.imgur.com/PEnJm.png'), -webkit-linear-gradient(left, rgba(21,112,145,1) 0%,rgba(36,138,166,1) 100%); background: url('http://i.stack.imgur.com/PEnJm.png'), -o-linear-gradient(left, rgba(21,112,145,1) 0%,rgba(36,138,166,1) 100%); background: url('http://i.stack.imgur.com/PEnJm.png'), -ms-linear-gradient(left, rgba(21,112,145,1) 0%,rgba(36,138,166,1) 100%); background: url('http://i.stack.imgur.com/PEnJm.png'), linear-gradient(to right, rgba(21,112,145,1) 0%,rgba(36,138,166,1) 100%); background-blend-mode: multiply; } 

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

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