我需要创建一个 svg 形状,具有这种外观:
我正在尝试使用属性 stroke-dasharray 和 stroke-dashoffset 来实现这一点,但我做不到。
例子:
CSS:
@import url(https://fonts.googleapis.com/css?family=Roboto:300,400,500);
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
*:after, *:before {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
html {
height: 100%;
}
body {
height: 100%;
overflow: hidden;
padding: 0;
margin: 0;
background-color: #333;
padding-top: 50px;
}
.row {
width: 700px;
margin: 0 auto;
overflow: hidden;
}
.col {
float: left;
width: 33.33333%;
text-align: center;
}
.button {
position: relative;
height: 50px;
padding: 0 10px;
width: 180px;
font-family: 'Roboto', sans-serif;
text-transform: uppercase;
display: inline-block;
cursor: pointer;
}
.button .shape {
stroke-dasharray: 45, 180px;
stroke-dashoffset: 18px;
}
.button svg {
position: relative;
z-index: 1;
display: block;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 0;
}
.button .content {
color: #2980b9;
line-height: 50px;
text-align: center;
z-index: 2;
position: relative;
vertical-align: middle;
-moz-transition: all 0.4s ease-in-out;
-o-transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
transition: all 0.4s ease-in-out;
}
.button:hover .content {
color: #e74c3c;
}
.button:hover .shape {
stroke: #000;
}
.button .shape {
fill: transparent;
stroke: #fff;
-moz-transition: all 0.4s ease-in-out;
-o-transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
transition: all 0.4s ease-in-out;
stroke-width: 6px;
}
HTML:
<div class='row'>
<div class='col'>
<div class='button'>
<svg xmlns='http://www.w3.org/2000/svg'>
<rect class='shape' height='100%' width='100%'></rect>
</svg>
<div class='content'>Hello</div>
</div>
</div>
</div>