HTML+CSS 流光卡片

admin admin 2024-08-11 1965 阅读 0 评论

实现了一个带有旋转动画的文字效果,包括容器、背景、文字和文字边框的样式,以及背景的动画效果。

Code

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>流光卡片</title>
    <link rel="stylesheet" href="./53-流光卡片.css">
</head>

<body>
    <div class="box">
        <span></span>
        <h2>01</h2>
    </div>
</body>

</html>
CSS
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #0c1022;
}

.box {
    position: relative;
    width: 300px;
    height: 400px;
    background: rgba(0, 0, 0, .75);
    border-radius: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.box::after {
    content: "";
    position: absolute;
    width: 500px;
    height: 500px;
    background-image: conic-gradient(transparent, transparent, transparent, #de44d4);
    animation: animate 4s linear infinite;
    animation-delay: -2s;
}

.box::before {
    content: "";
    position: absolute;
    width: 500px;
    height: 500px;
    background-image: conic-gradient(transparent, transparent, transparent, #00ccff);
    animation: animate 4s linear infinite;
}

@keyframes animate {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.box span {
    position: absolute;
    inset: 5px;
    border-radius: 16px;
    background: #0c1022;
    z-index: 1;
}

.box h2 {
    position: relative;
    z-index: 2;
    color: #fff;
    font-size: 10em;
}

实现思路拆分

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

设置所有元素的外边距和内边距为0,并使用border-box盒模型。

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #0c1022;
}

设置页面的样式,采用flex布局,水平和垂直居中,最小高度为100vh,背景颜色为深蓝色。

.box {
  position: relative;
  width: 300px;
  height: 400px;
  background: rgba(0, 0, 0, .75);
  border-radius: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

设置容器的样式,包括定位、宽度、高度、背景颜色、圆角、采用flex布局、水平和垂直居中、溢出隐藏。

.box::after {
  content: "";
  position: absolute;
  width: 500px;
  height: 500px;
  background-image: conic-gradient(transparent, transparent, transparent, #de44d4);
  animation: animate 4s linear infinite;
  animation-delay: -2s;
}

.box::before {
  content: "";
  position: absolute;
  width: 500px;
  height: 500px;
  background-image: conic-gradient(transparent, transparent, transparent, #00ccff);
  animation: animate 4s linear infinite;
}

设置容器的背景样式,包括定位、宽度、高度、背景渐变、动画效果和动画延迟。

@keyframes animate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

定义背景动画的关键帧,使背景颜色在4秒内旋转360度。

.box span {
  position: absolute;
  inset: 5px;
  border-radius: 16px;
  background: #0c1022;
  z-index: 1;
}

.box h2 {
  position: relative;
  z-index: 2;
  color: #fff;
  font-size: 10em;
}

设置文字和文字边框的样式,包括定位、内边距、圆角、背景颜色和层级。

打 赏 站 长
附件下载
上一篇 下一篇

相关阅读

发表评论

访客 访客
快捷回复: 表情:
评论列表 (有 0 条评论,1965人围观)