<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
html,
body {
padding: 0;
margin: 0;
font-family: 'PingFang SC';
}
.container {
display: flex;
align-items: center;
justify-content: center;
width: 100vw;
height: 100vh;
background: #2f3542;
}
.button-wrapper {
position: absolute;
width: 240px;
height: 60px;
text-align: center;
}
.rectangle {
stroke-width: 8px;
stroke: #ff6348;
fill: transparent;
stroke-dasharray: 100 500;
stroke-dashoffset: -374;
}
.btn {
color: white;
font-size: 18px;
letter-spacing: 6px;
position: relative;
top: -48px;
}
.button-wrapper:hover .rectangle {
animation: 0.5s extend linear forwards;
}
@keyframes extend {
to {
stroke-dasharray: 600;
stroke-dashoffset: 0;
stroke-width: 2;
}
}
</style>
</head>
<body>
<div class="container">
<div class="button-wrapper">
<svg width="240" height="60">
<rect class="rectangle" width="240" height="60"></rect>
<div class="btn">
按钮
</div>
</svg>
</div>
</div>
</body>
</html>
效果图: