Desired result
I'm trying to stack some CSS gradients together to replicate a fill pattern from Excel.
Problem
I have something that almost works, but it requires additional HTML elements and I'm not too sure I'm using blend-mode
correctly.
I know you can specify multiple background-blend-mode
in CSS, but I can't manage to make them work together on a single element.
My solution so far
I was able to get a decent solution using nested elements and two layers.
Using white as an intermediate step
The first layer uses background-blend-mode: darken;
with white and blue.
My solution looks a little bit different, but here is how Excel would show it:
My HTML/CSS: codepen link
<div class="example"></div>
.example {
--middle-color: #FFFFFF;
--outer-color: #4472C4;
width: 500px;
height: 150px;
background:
linear-gradient(to right, var(--outer-color), var(--middle-color) 50%, var(--outer-color) 100%),
linear-gradient(to bottom, var(--outer-color), var(--middle-color) 50%, var(--outer-color) 100%);
background-blend-mode: darken;
}
Using white again, then stacking
To make the red portion, I again use white, but this time with background-blend-mode: lighten;
Finally, I combine the two layers with mix-blend-mode
Here is the implementation: codepen link
<div class="example">
<div class="inner"></div>
</div>
.example {
--middle-color: #FFFFFF;
--outer-color: #4472C4;
width: 500px;
height: 150px;
background:
linear-gradient(to right, var(--outer-color), var(--middle-color) 50%, var(--outer-color) 100%),
linear-gradient(to bottom, var(--outer-color), var(--middle-color) 50%, var(--outer-color) 100%);
background-blend-mode: darken;
}
.inner {
--middle-color: red;
--outer-color: #FFFFFF;
width: 100%;
height: 100%;
background:
linear-gradient(to right, var(--outer-color), var(--middle-color) 50%, var(--outer-color) 100%),
linear-gradient(to bottom, var(--outer-color), var(--middle-color) 50%, var(--outer-color) 100%);
background-blend-mode: lighten;
mix-blend-mode: multiply;
}
I'm not 100% sure that mix-blend-mode: multiply;
is the correct choice, but I am a software developer who has not studied graphic design and blending at all.