创建一个圆形箭头
Create a rounded arrow
我正在尝试制作一个如下所示的箭头:
然而,这是我能得到的最接近的结果:
.button {
margin: 4em 0;
padding: 2em;
width: 15%;
margin: 0 auto;
text-align: center;
background-color: #000000;
color: #ffffff;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-moz-flex-flow: row wrap;
-webkit-flex-flow: row wrap;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
webkit-justify-content: center;
justify-content: center;
}
.curved-arrow {
display: inline-block;
border-top: 10px solid #fff;
border-bottom: 10px solid #fff;
border-left: 30px solid #fff;
border-top-right-radius: 100%;
border-bottom-right-radius: 100%;
}
<div class="button">
<div class="curved-arrow"></div>
</div>
这可能吗?我知道我可以使用图像,但我的设计师制作了多种颜色的图像以供整个网站使用,我宁愿只使用 CSS 作为形状。
如果很难看的话,左边是一条从上到下的平直线,右边是向中间弯曲的。
是这样的吗?
#arrow-base {
width: 120px;
height: 80px;
background: red;
}
#arrow {
width: 0;
height: 0;
border-top: 16px solid transparent;
border-bottom: 16px solid transparent;
border-left: 32px solid white;
display: inline-block;
margin: 24px 44px;
border-radius: 2px;
}
<div id="arrow-base">
<div id="arrow">
<!-- should be empty -->
</div>
</div>
我想我做了一些非常相似的东西,也许你可以改变一些 margins/widths 或高度:
#arrow{
display: block;
box-sizing: content-box;
float: none;
width: 130px;
height: 50px;
top: auto;
right: auto;
bottom: auto;
left: auto;
margin: 0;
padding: 0;
overflow: visible;
outline: none;
border: 0 solid rgba(0,0,0,1);
-webkit-border-radius: 50%;
border-radius: 50%;
background: #1abc9c;
box-shadow: none;
text-shadow: none;
margin-left:-65px;
}
#arrow:after {
position:absolute;
left:-65px;
width:65px;
background:transparent;
content:'';
}
它应该是一个椭圆形,我用 :after
隐藏了一半(相当肮脏的把戏)
但是,我建议您使用 CSS 精灵图,我想它们应该最适合您的情况,因为 CSS 形状对于浏览器来说不是那么容易阅读。
希望对您有所帮助! :)
这是我的看法。一点不像我想要的那么尖锐,但它更接近一点。编辑:second take 使用两个伪元素来帮助锐化角度。
.button { margin: 4em 0; padding: 2em; width: 15%; margin: 0 auto; text-align: center; background-color: #000000; color: #ffffff; isplay: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -moz-flex-flow:row wrap; -webkit-flex-flow:row wrap; -ms-flex-flow:row wrap; flex-flow:row wrap; webkit-justify-content: center; justify-content: center; }
.curved-arrow {
position: relative;
display: inline-block;
height: 36px;
width: 56px;
overflow: hidden;
}
.curved-arrow:after {
content: '';
position: absolute;
right: 0;
top: 0;
border-radius: 0 100% 0 0;
height: 50%;
width: 200%;
background: #FFF;
}
.curved-arrow:before {
content: '';
position: absolute;
right: 0;
bottom: 0;
border-radius: 0 0 100% 0;
height: 50%;
width: 200%;
background: #FFF;
}
<div class="button">
<div class="curved-arrow"></div>
</div>
SVG
CSS 边界半径不会让您轻松获得您正在寻找的准确输出。我建议使用带有一个 quadratic bezier command :
路径元素的内联 SVG
svg{width:100px;}
<svg viewbox="0 0 20 8">
<path d="M0 0 Q 30 4 0 8" />
</svg>
然后您可以使用 CSS 填充 属性 为箭头着色,请参阅此 fiddle (credits to @Nick R 以了解评论中发布的示例)
CSS
你也可以使用 border-radius 的 2 个值 属性(见 MDN 了解它是如何工作的解释)它很简单但是它不会让你制作箭头'point' 与您的图像一样清晰:
.curved-arrow {
width:40px; height:25px;
background:#000;
border-top-right-radius:100% 50%;
border-bottom-right-radius:100% 50%;
}
<div class="curved-arrow"></div>
CSS
这只需要一点花哨的 border-radius
样式来实现您想要的形状。
.container {
width: 100px;
height: 100px;
background: red;
position: relative;
}
.arrow {
width: 50px;
height: 30px;
position: absolute;
top: 32px;
left: 25%;
border-radius: 0px 100% 100% 0px / 0 50% 50% 0;
background: white;
}
<div class="container">
<div class="arrow"></div>
</div>
如果你想在单个元素中使用它,你可以像这样使用伪元素。
.arrow {
width: 100px;
height: 100px;
background: red;
position: relative;
}
.arrow:before {
content: '';
width: 50px;
height: 30px;
position: absolute;
top: 32px;
left: 25%;
border-radius: 0px 100% 100% 0px / 0 50% 50% 0;
background: white;
}
<div class="arrow"></div>
SVG
一个不错的替代方法是使用 SVG 来创建这种形状,这也使它完全响应。
<svg width="100px" height="100px" viewbox="0 0 20 20" style="background: red;">
<path d="M5,7
Q15,7 15,10
Q15,13 5,13z" fill="white"></path>
</svg>
我正在尝试制作一个如下所示的箭头:
然而,这是我能得到的最接近的结果:
.button {
margin: 4em 0;
padding: 2em;
width: 15%;
margin: 0 auto;
text-align: center;
background-color: #000000;
color: #ffffff;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-moz-flex-flow: row wrap;
-webkit-flex-flow: row wrap;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
webkit-justify-content: center;
justify-content: center;
}
.curved-arrow {
display: inline-block;
border-top: 10px solid #fff;
border-bottom: 10px solid #fff;
border-left: 30px solid #fff;
border-top-right-radius: 100%;
border-bottom-right-radius: 100%;
}
<div class="button">
<div class="curved-arrow"></div>
</div>
这可能吗?我知道我可以使用图像,但我的设计师制作了多种颜色的图像以供整个网站使用,我宁愿只使用 CSS 作为形状。
如果很难看的话,左边是一条从上到下的平直线,右边是向中间弯曲的。
是这样的吗?
#arrow-base {
width: 120px;
height: 80px;
background: red;
}
#arrow {
width: 0;
height: 0;
border-top: 16px solid transparent;
border-bottom: 16px solid transparent;
border-left: 32px solid white;
display: inline-block;
margin: 24px 44px;
border-radius: 2px;
}
<div id="arrow-base">
<div id="arrow">
<!-- should be empty -->
</div>
</div>
我想我做了一些非常相似的东西,也许你可以改变一些 margins/widths 或高度:
#arrow{
display: block;
box-sizing: content-box;
float: none;
width: 130px;
height: 50px;
top: auto;
right: auto;
bottom: auto;
left: auto;
margin: 0;
padding: 0;
overflow: visible;
outline: none;
border: 0 solid rgba(0,0,0,1);
-webkit-border-radius: 50%;
border-radius: 50%;
background: #1abc9c;
box-shadow: none;
text-shadow: none;
margin-left:-65px;
}
#arrow:after {
position:absolute;
left:-65px;
width:65px;
background:transparent;
content:'';
}
它应该是一个椭圆形,我用 :after
隐藏了一半(相当肮脏的把戏)
但是,我建议您使用 CSS 精灵图,我想它们应该最适合您的情况,因为 CSS 形状对于浏览器来说不是那么容易阅读。
希望对您有所帮助! :)
这是我的看法。一点不像我想要的那么尖锐,但它更接近一点。编辑:second take 使用两个伪元素来帮助锐化角度。
.button { margin: 4em 0; padding: 2em; width: 15%; margin: 0 auto; text-align: center; background-color: #000000; color: #ffffff; isplay: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -moz-flex-flow:row wrap; -webkit-flex-flow:row wrap; -ms-flex-flow:row wrap; flex-flow:row wrap; webkit-justify-content: center; justify-content: center; }
.curved-arrow {
position: relative;
display: inline-block;
height: 36px;
width: 56px;
overflow: hidden;
}
.curved-arrow:after {
content: '';
position: absolute;
right: 0;
top: 0;
border-radius: 0 100% 0 0;
height: 50%;
width: 200%;
background: #FFF;
}
.curved-arrow:before {
content: '';
position: absolute;
right: 0;
bottom: 0;
border-radius: 0 0 100% 0;
height: 50%;
width: 200%;
background: #FFF;
}
<div class="button">
<div class="curved-arrow"></div>
</div>
SVG
CSS 边界半径不会让您轻松获得您正在寻找的准确输出。我建议使用带有一个 quadratic bezier command :
路径元素的内联 SVGsvg{width:100px;}
<svg viewbox="0 0 20 8">
<path d="M0 0 Q 30 4 0 8" />
</svg>
然后您可以使用 CSS 填充 属性 为箭头着色,请参阅此 fiddle (credits to @Nick R 以了解评论中发布的示例)
CSS
你也可以使用 border-radius 的 2 个值 属性(见 MDN 了解它是如何工作的解释)它很简单但是它不会让你制作箭头'point' 与您的图像一样清晰:
.curved-arrow {
width:40px; height:25px;
background:#000;
border-top-right-radius:100% 50%;
border-bottom-right-radius:100% 50%;
}
<div class="curved-arrow"></div>
CSS
这只需要一点花哨的 border-radius
样式来实现您想要的形状。
.container {
width: 100px;
height: 100px;
background: red;
position: relative;
}
.arrow {
width: 50px;
height: 30px;
position: absolute;
top: 32px;
left: 25%;
border-radius: 0px 100% 100% 0px / 0 50% 50% 0;
background: white;
}
<div class="container">
<div class="arrow"></div>
</div>
如果你想在单个元素中使用它,你可以像这样使用伪元素。
.arrow {
width: 100px;
height: 100px;
background: red;
position: relative;
}
.arrow:before {
content: '';
width: 50px;
height: 30px;
position: absolute;
top: 32px;
left: 25%;
border-radius: 0px 100% 100% 0px / 0 50% 50% 0;
background: white;
}
<div class="arrow"></div>
SVG
一个不错的替代方法是使用 SVG 来创建这种形状,这也使它完全响应。
<svg width="100px" height="100px" viewbox="0 0 20 20" style="background: red;">
<path d="M5,7
Q15,7 15,10
Q15,13 5,13z" fill="white"></path>
</svg>