如何使用CSS创建多色“自由流动”渐变

huangapple go评论64阅读模式
英文:

How to create a multi color "free flow" gradient with CSS

问题

我想创建一个多彩的“自由流动”CSS渐变背景。它应该看起来像这样:
如何使用CSS创建多色“自由流动”渐变

似乎我需要使用背景混合模式。例如屏幕:
background-blend-mode: screen;

渐变有五种颜色:
如何使用CSS创建多色“自由流动”渐变
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:

如何使用CSS创建多色“自由流动”渐变

It seems I need to use a background blend mode. For example screen:

background-blend-mode: screen;

The gradient has five colors:

如何使用CSS创建多色“自由流动”渐变

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 -->

&lt;div class=&quot;spectrum-background&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

It's not perfectly identical but something you can play with further.

huangapple
  • 本文由 发表于 2023年6月8日 17:42:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430542.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定