英文:
How to create a multi color "free flow" gradient with CSS
问题
我想创建一个多彩的“自由流动”CSS渐变背景。它应该看起来像这样:
似乎我需要使用背景混合模式。例如屏幕:
background-blend-mode: screen;
渐变有五种颜色:
A: #ecedee
B: #fff0be
C: #fbdce7
D: #e2fae1
E: #d3d5ed
我能找到的最接近的解决方案是这个博客文章中的“光谱背景”:
.spectrum-background {
background:
linear-gradient(red, transparent),
linear-gradient(to top left, lime, transparent),
linear-gradient(to top right, blue, transparent);
background-blend-mode: screen;
}
但我不确定如何添加更多颜色并将它们定位到附加的图像上。我希望有人能帮忙。
英文:
I want to create a multi colored "free flow" CSS gradient background. It should look something like this:
It seems I need to use a background blend mode. For example screen:
background-blend-mode: screen;
The gradient has five colors:
A: #ecedee
B: #fff0be
C: #fbdce7
D: #e2fae1
E: #d3d5ed
The closest solution I can find is the "Spectrum background" in this blog post
.spectrum-background {
background:
linear-gradient(red, transparent),
linear-gradient(to top left, lime, transparent),
linear-gradient(to top right, blue, transparent);
background-blend-mode: screen;
}
But I am not sure how I can add more colors and position them like on the attached image. I hope someone can help.
答案1
得分: 1
你当然可以添加更多的渐变和颜色,但使用 blend-mode: screen
的棘手之处在于,不透明颜色重叠的地方会变成白色。
我发现只使用渐变更容易处理,不使用混合效果。以下是我能够创建以匹配您期望结果的内容:
.spectrum-background {
width: 500px;
height: 1000px;
background:
linear-gradient(150deg, #ecedee, transparent 30%),
linear-gradient(330deg, rgb(210, 206, 242), transparent 30%),
linear-gradient(225deg, #fff0be, #fbdce7, #e2fae1, powderblue);
}
<div class="spectrum-background"></div>
它不是完全相同的效果,但您可以进一步调整。
英文:
You can certainly add more gradients and colors but the tricky part with blend-mode: screen
is that it becomes white wherever opaque colors overlap.
I found it much easier to work with just gradients, without blending. Here's what I could come up with to match your desired result:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.spectrum-background {
width: 500px;
height: 1000px;
background:
linear-gradient(150deg, #ecedee, transparent 30%),
linear-gradient(330deg, rgb(210, 206, 242), transparent 30%),
linear-gradient(225deg, #fff0be, #fbdce7, #e2fae1, powderblue);
}
<!-- language: lang-html -->
<div class="spectrum-background"></div>
<!-- end snippet -->
It's not perfectly identical but something you can play with further.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论