使用 css 创建 S 形曲线
Creating s-shaped curve using css
我想使用 css 创建如下图所示的曲线。
我正在尝试这样的事情:
.curve {
background-color: #8aa7ca;
height: 65px;
width: 160px;
-moz-border-radius-bottomright: 25px 50px;
border-bottom-right-radius: 25px 50px;
}
<div class="curve">
<p>This is a sample text.</p>
</div>
请帮帮我
SVG
正如 Harry 在评论中所建议的那样,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
当然这在 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>
SVG
在svg this can be created using a single path
<svg height="300px" viewBox="0 0 100 100">
<path fill="CornFlowerBlue" d="M0,0
100,0
C50,20 50,80 0,100 Z" />
</svg>
如果您愿意,您可以使用纯 CSS 来制作它。
这使用大框阴影创建第二条曲线:
.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。
然后您所要做的就是为生成的 wave 复制粘贴代码。
这是我用过的:
svg wage generator
我想使用 css 创建如下图所示的曲线。
我正在尝试这样的事情:
.curve {
background-color: #8aa7ca;
height: 65px;
width: 160px;
-moz-border-radius-bottomright: 25px 50px;
border-bottom-right-radius: 25px 50px;
}
<div class="curve">
<p>This is a sample text.</p>
</div>
请帮帮我
SVG
正如 Harry 在评论中所建议的那样,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
当然这在 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>
SVG
在svg this can be created using a single path
<svg height="300px" viewBox="0 0 100 100">
<path fill="CornFlowerBlue" d="M0,0
100,0
C50,20 50,80 0,100 Z" />
</svg>
如果您愿意,您可以使用纯 CSS 来制作它。
这使用大框阴影创建第二条曲线:
.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。
然后您所要做的就是为生成的 wave 复制粘贴代码。
这是我用过的:
svg wage generator