html - 如何创建波浪形CSS?

标签 html css css-shapes

请查看下面的图片,了解我要创建的内容:

enter image description here

到目前为止,我有以下内容,但它需要更“频繁”,例如增加正弦或余弦波的频率。



#wave {
  position: relative;
  height: 70px;
  width: 600px;
  background: #e0efe3;
}

#wave:before {
  content: "";
  display: block;
  position: absolute;
  border-radius: 100% 50%;
  width: 340px;
  height: 80px;
  background-color: white;
  right: -5px;
  top: 40px;
}

#wave:after {
  content: "";
  display: block;
  position: absolute;
  border-radius: 100% 50%;
  width: 300px;
  height: 70px;
  background-color: #e0efe3;
  left: 0;
  top: 27px;
}

<div id="wave"></div>

最佳答案

这是使用radial-gradient和CSS变量的想法,您可以在其中轻松控制形状:



.wave {
  --c:red;   /* Color */
  --t:5px;   /* Thickness */
  --h:50px;  /* Height (vertical distance between two curve) */
  --w:120px; /* Width  */
  --p:13px;  /* adjust this to correct the position when changing the other values*/
  background:
    radial-gradient(farthest-side at 50% calc(100% + var(--p)), transparent 47%, var(--c) 50% calc(50% + var(--t)),transparent calc(52% + var(--t))),
    radial-gradient(farthest-side at 50% calc(0%   - var(--p)), transparent 47%, var(--c) 50% calc(50% + var(--t)),transparent calc(52% + var(--t)));
    
  background-size:var(--w) var(--h);
  background-position:calc(var(--w)/2) calc(var(--h)/2),0px calc(var(--h)/2);
  
  
  border:1px solid;
  margin:5px 0;
  display:inline-block;
  width:300px;
  height:150px;
}

<div class="wave"></div>

<div class="wave" style="--w:200px;--h:40px;--p:10px; --t:8px;--c:purple"></div>

<div class="wave" style="--w:80px ;--h:20px;--p:5px;  --t:3px;--c:blue;"></div>

<div class="wave" style="--w:100px;--h:30px;--p:14px;--t:10px;--c:green;"></div>





Wavy shape CSS

关于html - 如何创建波浪形CSS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58145722/

相关文章:

html - 具有绝对内容的表格单元格的宽度

javascript - 无法从 Jquery 插件绘制到 HTML Canvas

html - 如何设计带有输入和文本区域的 Bootstrap 表单?

css - 带有三 Angular 形的工具提示

html - 如何用边界边上的链接创建一个圆

php - 如何根据动态创建的输入框更新MySQL数据库中的特定记录

javascript - 如何在不对特定行进行排序的情况下使 html 表可排序?

css - 是否可以在 CSS 中抽象出颜色主题定义

html - 菜单栏固定时元素在菜单栏上滚动

html - 如何使用div绘制曲线?