利用伪元素::before和::after制作旋转边框的按钮
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
html,
body {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.btn {
/* outline: 4px solid #000; */
width: 80px;
height: 30px;
border-radius: 3px;
display: flex;
justify-content: center;
align-items: center;
position: relative;
overflow: hidden;
}
.btn::before {
content: '';
background: rgb(188, 27, 27);
position: absolute;
height: 200%;
width: 200%;
border-radius: 3px;
animation: border-line 3s infinite linear;
z-index: -2;
transform-origin: 0 0;
top: 50%;
left: 50%;
}
@keyframes border-line {
to {
transform: rotate(1turn);
}
}
.btn::after {
content: '';
background: #fff;
height: calc(100% - 4px);
width: calc(100% - 4px);
position: absolute;
z-index: -1;
}
</style>
</head>
<body>
<div class="btn">按钮</div>
</body>
</html>