html结构
<div class="box">
<div class="text"> CSS</div>
</div>
CSS:
父盒子样式
.box {
width: 200px;
height: 300px;
background-color: rgb(15, 15, 15);
position: relative;
left: 100px;
top: 100px;
border-radius: 1px;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
字体样式
.box .text {
color: white;
font-size: 4em;
text-shadow: 2px 2px pink;
z-index: 1;
}
为父盒子添加before伪元素
.box::before {
content: '';
display: block;
position: absolute;
width: 100px;
height: 360px;
background: linear-gradient(#00ccff, #d500f9);
animation: text 6s linear infinite; //为伪元素设置动画
border-radius: 5px;
}
为父盒子添加after伪元素
.box::after {
content: '';
position: absolute;
inset: 6px;
background-color: black;
}
定义动画
/* 定义动画 */
@keyframes text {
0% {
transform: rotate(0deg);
}
50% {
transform: rotate(180deg);
}
100% {
transform: rotate(360deg);
}
}