I have two divs with distinct gradient background and I need to create a S-Shape curve between them.
Here's the example fiddle for gradient divs: https://jsfiddle.net/JerryGoyal/rjyfc46c/2/
<div id="section1">
</div>
<div id="section2">
</div>
#section1{
height:200px;
background: linear-gradient(to bottom right, #ad3, #add);
}
#section2{
height:200px;
background: linear-gradient(to bottom right, #de350b, #0065ff);
}
There are couple of things which crossed my mind but:
- svg: don't know how to handle other gradient div.
- border-radius: failed to get truly S-like curve plus it gets ugly when I resize the screen.
- clip-path: not supported by some browsers https://caniuse.com/css-clip-path
- png image: nope! needs to be dynamic content.
any help would be appreciated!
P.S: a must read for future readers: https://css-tricks.com/creating-non-rectangular-headers/
Here is a solution using linearGradient with SVG.
Here is also a useful online tool to easily edit the shape (simply append the path to the url to edit it
http://jxnblk.com/paths/?d=M0 10 C30 28 38 0 64 10 L64 0 L0 0 Z
)Another idea with the same SVG used as a background so you can easily handle content above it:
In case you want a pure CSS solution with no SVG involved here is one using
mask
and radial-gradient:Adjust the different values to control the curve. The trick is to make sure both are the same and start at the same point to create a contiguous shape. You can introduce CSS variables to easily control this:
To make things more funny we can add a border between both gradient following the curve where we can place another gradient!