简体   繁体   English

如何使用css创建波形

[英]How to create wave shape using css

I am trying to display an li element as a wave. 我试图将li元素显示为wave。 I don't want to use any background images but the border-radius doesn't support negative values. 我不想使用任何背景图像,但border-radius不支持负值。 I hope you can help me. 我希望你能帮助我。

在CSS中这是可能的吗?

The closest I can get is this using only css. 我能得到的最接近的是这只使用css。

 .one { position: absolute; top: 22px; left: 19px; width: 230px; height: 180px; background: #0F1E3C; border-radius: 100%; clip: rect(70px, auto, auto, 45px); transform:rotate(90deg); } .one:before { content: ''; position: absolute; top: -15px; left: -62px; width: 200px; height: 200px; background: white; border-radius: 100%; } .two { position: absolute; top: 156px; left: 59px; width: 230px; height: 180px; background: #0F1E3C; border-radius: 100%; clip: rect(70px, auto, auto, 45px); transform:rotate(-90deg); } .two:before { content: ''; position: absolute; top: -15px; left: -62px; width: 200px; height: 200px; background: white; border-radius: 100%; } 
 <div class="one"></div> <div class="two"></div> 

Whilst SVG would be a much better option here, you could use a border-like hack to create the basis of this shape. 虽然SVG将在这里是一个更好的选择,你可以使用一个边界样黑客创建这种形状的基础。

Here is a basic example for this kind of shape, although I will say there is a lot of room for improvement: 这是这种形状的一个基本例子,虽然我会说还有很大的改进空间:

 div { position:relative; height:100px; width:100px; background:lightgray; overflow:hidden; } div:before { content:""; position:absolute; top:calc(-100% - 25px); left:00%; height:200%; width:200%; border-radius:50%; background:cornflowerblue; border-bottom:50px solid blue; } div:nth-child(2) { transform:rotate(180deg); margin-left:40px; margin-top:-25px; } 
 <div></div> <div></div> 


A Quick SVG version: 快速SVG版本:

 <svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="407pt" height="126pt" viewBox="0 0 407 126"> <g transform="translate(0,126) scale(0.1,-0.1)" fill="#000000" stroke="none"> <path d="M43 1223 c-4 -21 -8 -119 -7 -218 0 -169 2 -185 28 -265 153 -466 545 -728 1030 -689 276 23 694 112 1116 239 175 53 375 99 501 116 149 19 363 15 453 -10 134 -37 273 -132 351 -241 26 -36 42 -51 46 -42 4 7 13 58 20 115 29 239 -44 492 -201 700 -99 132 -238 236 -405 303 l-76 30 -417 -3 -417 -4 -190 -37 c-104 -21 -275 -58 -380 -82 -316 -73 -466 -96 -678 -102 -124 -4 -218 -2 -280 7 -175 23 -341 91 -437 177 l-49 44 -8 -38z" /> </g> </svg> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM