【发布时间】:2018-09-21 04:50:53
【问题描述】:
我们如何使用 CSS 制作这个形状?
我可以使用 CSS 编写以下代码,但生成的形状输出有点偏离。我们可以使用 CSS 做到这一点吗?
.btn-arrow {
width: 15px;
height: 24px;
border: 2px solid red;
border-top-right-radius: 40px;
border-bottom-right-radius: 40px;
border-left: 0;
display: inline-block;
position: relative;
}
.btn-arrow:after,
.btn-arrow:before {
right: 100%;
top: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
}
.btn-arrow:after {
border-right-color: white;
border-width: 12px;
margin-top: -12px;
}
.btn-arrow:before {
border-right-color: red;
border-width: 14px;
margin-top: -14px;
}
body {
padding: 20px;
}
<div class="btn-arrow"></div>
【问题讨论】:
-
使用 SVG 而不是 HTML 和 CSS 会更容易
-
你的形状的圆角持续超过 180 度,所以你不能指望用两个边界半径来实现,每个边界半径都覆盖/跨越一个精确的 90 度部分。您必须从一个完全圆形的元素开始,然后将它的一部分与实际的“直角/直边”形状重叠......这意味着,如果您需要它是透明的/在多色背景上工作,这个马上就出来了。
-
谢谢大家的指导。我会选择 SVG
-
我有一个 CSS 解决方案,如果你给我一些时间来构建它。