I was wondering if it is possible to create a background effect like in the image below using just one div.
I know how to achieve it with two divs, but my situation would make it really easy if it could be done in one div (maybe using :after ???). The code for the gradients is:
.bg-green {
background-image: linear-gradient(-180deg, #95D428 0%, #20560B 100%);
}
.bg-red {
background-image: linear-gradient(-180deg, #F5515F 0%, #8E0A1E 100%;
}
Thanks :)
You can get this effect, but you will need to set overflow hidden on the div and to set the background in a after pseudo class
The after is rotated to get the inclined separation. The dimensions need to be bigger so as not to show missing corners.
And then, you assign the 2 linear gradients as 2 separate background-images,inclined an additional 30deg to compensate for the base inclination
Yes, this is possible using a single
div
with a :pseudo-element.What you could do is add the second
linear-gradient
to its:after
:pseudo-element. Notice the use ofrgba(r, b, g, a)
instead of hex colors. This way you could control the opacity of the secondlinear-gradient
by changing its alpha value.If you want the exact same gradient colors that you've posted in your question, you'll need
clipPath
.