在CSS中两个渐变div之间创建曲线的好方法?

Jer*_*yal 9 html css linear-gradients css-shapes

我有两个具有不同渐变背景的div,我需要在它们之间创建一个S形曲线.

在此输入图像描述

这是渐变div的示例小提琴: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);
}
Run Code Online (Sandbox Code Playgroud)

我想到了几件事情,但是:

- svg:不知道如何处理其他渐变div.
- border-radius:无法获得真正类似S的曲线加上当我调整屏幕大小时它会变得难看.
- clip-path:某些浏览器不支持https://caniuse.com/css-clip-path
- png image: nope!需要是动态内容.

任何帮助,将不胜感激!


PS:未来读者必读:https://css-tricks.com/creating-non-rectangular-headers/

Tem*_*fif 10

这是一个使用linearGradient和SVG 的解决方案.

.container {
  width: 500px;
  height: 200px;
  background:linear-gradient(to bottom right, #de350b, #0065ff);
}
svg {
  width:100%;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
  <svg mlns='http://www.w3.org/2000/svg' viewBox="0 0 64 64">
    <defs>
    <linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="100%">
      <stop offset="0%" stop-color="#ad3" />
      <stop offset="100%" stop-color="#add" />
    </linearGradient>
  </defs>
    <path d='M0 10 C30 28 38 0 64 10 L64 0 L0 0 Z'  fill="url(#grad)"/>
  </svg>
</div>
Run Code Online (Sandbox Code Playgroud)

这里也是一个有用的在线工具,可以轻松编辑形状(只需将路径附加到网址进行编辑http://jxnblk.com/paths/?d=M0 10 C30 28 38 0 64 10 L64 0 L0 0 Z)


使用相同SVG作为背景的另一个想法,以便您可以轻松处理其上方的内容:

.container {
  width: 500px;
  height: 200px;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="500" ><defs><linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="%23ad3" /><stop offset="100%" stop-color="%23add" /></linearGradient></defs><path d="M0 10 C30 28 38 0 64 10 L64 0 L0 0 Z"  fill="url(%23grad)"/></svg>'), 
  linear-gradient(to bottom right, #de350b, #0065ff);
  
  display:flex;
  justify-content:space-around;
  align-items:center;
  flex-direction:column;
  color:#fff;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
<p>TOP</p>
<p>BOTTOM</p>
</div>
Run Code Online (Sandbox Code Playgroud)