sdv*_*ksv 31 css geometry css3 responsive-design css-shapes
下面的代码将在<a>
元素正下方创建一个箭头:
.btn {
position: relative;
display: inline-block;
width: 100px;
height: 50px;
text-align: center;
color: white;
background: gray;
line-height: 50px;
text-decoration: none;
}
.btn:after {
content: "";
position: absolute;
bottom: -10px;
left: 0;
width: 0;
height: 0;
border-width: 10px 50px 0 50px;
border-style: solid;
border-color: gray transparent transparent transparent;
}
Run Code Online (Sandbox Code Playgroud)
<a href="#" class="btn">Hello!</a>
Run Code Online (Sandbox Code Playgroud)
问题是我们必须指示链接宽度以获得适当大小的箭头,因为我们无法以像素为单位指示边框宽度.
如何制作响应三角形百分比?
web*_*iki 52
您可以使用倾斜和旋转的伪元素在链接下创建响应三角形:
DEMO(调整结果窗口的大小以查看它是如何反应的)
三角形保持它与padding-bottom
属性的纵横比.
如果您希望形状根据其内容调整其大小,则可以删除.btn
类中的宽度
.btn {
position: relative;
display: inline-block;
height: 50px; width: 50%;
text-align: center;
color: white;
background: gray;
line-height: 50px;
text-decoration: none;
padding-bottom: 15%;
background-clip: content-box;
overflow: hidden;
}
.btn:after {
content: "";
position: absolute;
top:50px; left: 0;
background-color: inherit;
padding-bottom: 50%;
width: 57.7%;
z-index: -1;
transform-origin: 0 0;
transform: rotate(-30deg) skewX(30deg);
}
/** FOR THE DEMO **/
body {
background: url('http://i.imgur.com/qi5FGET.jpg');
background-size: cover;
}
Run Code Online (Sandbox Code Playgroud)
<a href="#" class="btn">Hello!</a>
Run Code Online (Sandbox Code Playgroud)
有关响应三角形以及如何制作它们的更多信息,您可以查看 具有变换旋转的三角形(简单和花式响应三角形)
Pro*_*cop 14
另一个解决方案是使用CSS剪辑路径从彩色块中剪切三角形.但是没有IE支持,但可以用于内部工具等.
用SCSS编写以方便使用.
.outer {
background: orange;
width: 25%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 1em;
p {
margin: 0;
text-align: center;
color: #fff;
}
&:after {
content: '';
position: absolute;
top: 100%;
left: 0;
right: 0;
padding-bottom: 10%;
background: orange;
-webkit-clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
}
}
Run Code Online (Sandbox Code Playgroud)
我发现适用于任何宽度/高度的解决方案.你可以使用两个带linear-gradient
背景的伪元素,像这样,(小提琴):
.btn {
position: relative;
display: inline-block;
width: 100px;
height: 50px;
text-align: center;
color: white;
background: gray;
line-height: 50px;
text-decoration: none;
}
.btn:before {
content: "";
position: absolute;
top: 100%;
right: 0;
width: 50%;
height: 10px;
background: linear-gradient(to right bottom, gray 50%, transparent 50%)
}
.btn:after {
content: "";
position: absolute;
top: 100%;
left: 0;
width: 50%;
height: 10px;
background: linear-gradient(to left bottom, gray 50%, transparent 50%)
}
Run Code Online (Sandbox Code Playgroud)