文章数量
36
访客量
4952
访问量
9817

css特效之发光卡片

阅读量:1145
更新时间:2023-08-29 21:03:41

效果预览:效果预览
源码下载:关注公众号【RMRF】,回复【css12】可获取源码

使用@keyframes rotation关键帧动画,让圆环从 0 度旋转到 360 度,实现发光彩色圆环特效的卡片

HTML

<!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>
  <link rel="stylesheet" href="./css/index.css">
</head>

<body>
  <div class="container">
    <div class="card">
      <div class="card-content"></div>
    </div>
  </div>
</body>

</html>

CSS

* {
  padding: 0px;
  margin: 0px;
  }
  

.container {
display: flex;
align-items: center;
justify-content: center;
background: #202020;
height: 100vh;
}

.card {
position: relative;
height: 300px;
width: 250px;
background: #202020;
border-radius: 4px;
box-shadow: 0px 0px 10px 1px #000;
overflow: hidden;
}

.card::before {
position: absolute;
top: -100px;
content: '';
width: 250px;
height: 160%;
background: linear-gradient(90deg, transparent,
#ff1e00, transparent);
animation: rotation 5000ms infinite linear;
}

.card-content {
position: absolute;
top: 0.5%;
left: 0.5%;
width: 99%;
height: 99%;
background-color: #151515;
border-radius: 5px;
color: white;
}

@keyframes rotation {
0% {
transform: rotateZ(0deg);
}

0% {
transform: rotateZ(360deg);
}
}