正如哈里在评论中建议的那样,SVG将是您最好的选择,因为在CSS中使用双曲线如果不使用多个元素、伪元素或可能不支持的CSS3属性,则不可行。
SVG代表可缩放矢量图形。Web浏览器将其视为图像,但是您可以在SVG中添加文本和普通HTML元素。
它在所有浏览器中得到了很好的支持,可以在此查看:CanIUse
<svg width="466" height="603" viewbox="0 0 100 100" preserveAspectRatio="none">
<path d="M0,0
L100,0
C25,50 50,75 0,100z" fill="#8aa7ca" />
</svg>
当然,CSS 也能实现此功能,但需要使用伪元素 :before
和 :after
。但对于曲线效果不佳,会出现锯齿状。
div {
background: blue;
width: 50px;
height: 75px;
position: relative;
}
div:before {
content: '';
background-image: radial-gradient(circle at 100% 100%, rgba(204, 0, 0, 0) 100px, blue 100px);
position: absolute;
top: 0;
left: 100%;
width: 100px;
height: 75px;
}
div:after {
content: '';
position: absolute;
width: 50px;
height: 75px;
background: blue;
border-radius: 0 0 100% 0 / 0 0 100% 0;
top: 100%;
left: 0;
}
<div></div>
100, 0
中缺少了 L
。SVG 自动知道这是 Lineto
吗? - Si8.wrap {
position: relative;
height: 400px;
width: 100%;
margin: 0 auto;
max-width: 1024px;
}
.shape {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 50%;
overflow: hidden;
z-index: 10;
}
.shape:after {
content: "";
position: absolute;
top: 10%;
left: 0;
width: 100%;
height: 90%;
border-radius: 0 50% 0 0;
box-shadow: 0 0 0 999px lightgray;
}
.shape2 {
position: absolute;
top: 0;
left: 50%;
height: 100%;
width: 50%;
background: lightgray;
border-radius: 0 0 0 50%;
z-index: 10;
}
/******************************/
html,
body {
margin: 0;
padding: 0;
height: 100%;
vertical-align: top;
overflow: hidden;
background: cornflowerblue;
}
<div class="wrap">
<div class="shape"></div>
<div class="shape2">This will be where you can place the text to go down the right hand side of the slider</div>
</div>
我有一个类似的需求,但是发现这个任务的CSS对于我的知识水平来说过于复杂。因此,我使用了一个在线波形生成器。
通过它,你可以绘制所需的波形并生成SVG。
然后,你只需要复制粘贴生成的波形代码即可。
这是我使用的一个:
SVG波形生成器