一个简单的用CSS就就可以轻松实现的小效果:旋转边框
效果:
实现:
H5代码
<div class="box">
<h2>旋转边框</h2>
</div>
CSS代码
.box {
position: relative;
width: 150px;
height: 150px;
background-color: #0e1538;
border-radius: 15px;
margin: 200px auto;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.box h2 {
color: #fff;
font-size: 22px;
text-shadow: 2px 2px 4px #e74033;
z-index: 1;
}
.box::before {
content: '';
position: absolute;
top: 50%;
width: 100px;
height: 120%;
background: linear-gradient(#00ccff, #d500f9);
animation: rotate 3s linear infinite;
}
.box::after {
content: '';
position: absolute;
background: #0e1538;
inset: 6px;
border-radius: 14px;
}
@keyframes rotate {
from {
transform: rotate(0deg);
transform-origin: top;
}
to {
transform: rotate(360deg);
transform-origin: top;
}
}