HTML+CSS 流光卡片

admin 2024-08-11 88 阅读 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
* {
    margin0;
    padding0;
    box-sizing: border-box;
}

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

.box {
    position: relative;
    width300px;
    height400px;
    backgroundrgba(000, .75);
    border-radius20px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.box::after {
    content"";
    position: absolute;
    width500px;
    height500px;
    background-imageconic-gradient(transparent, transparent, transparent, #de44d4);
    animation: animate 4s linear infinite;
    animation-delay: -2s;
}

.box::before {
    content"";
    position: absolute;
    width500px;
    height500px;
    background-imageconic-gradient(transparent, transparent, transparent, #00ccff);
    animation: animate 4s linear infinite;
}

@keyframes animate {
    0% {
        transformrotate(0deg);
    }

    100% {
        transformrotate(360deg);
    }
}

.box span {
    position: absolute;
    inset5px;
    border-radius16px;
    background#0c1022;
    z-index1;
}

.box h2 {
    position: relative;
    z-index2;
    color#fff;
    font-size10em;
}

实现思路拆分

* {
  margin0;
  padding0;
  box-sizing: border-box;
}

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

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

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

.box {
  position: relative;
  width300px;
  height400px;
  backgroundrgba(000, .75);
  border-radius20px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

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

.box::after {
  content"";
  position: absolute;
  width500px;
  height500px;
  background-imageconic-gradient(transparent, transparent, transparent, #de44d4);
  animation: animate 4s linear infinite;
  animation-delay: -2s;
}

.box::before {
  content"";
  position: absolute;
  width500px;
  height500px;
  background-imageconic-gradient(transparent, transparent, transparent, #00ccff);
  animation: animate 4s linear infinite;
}

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

@keyframes animate {
  0% {
    transformrotate(0deg);
  }
  100% {
    transformrotate(360deg);
  }
}

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

.box span {
  position: absolute;
  inset5px;
  border-radius16px;
  background#0c1022;
  z-index1;
}

.box h2 {
  position: relative;
  z-index2;
  color#fff;
  font-size10em;
}

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

发表评论

快捷回复: 表情:
Addoil Applause Badlaugh Bomb Coffee Fabulous Facepalm Feces Frown Heyha Insidious KeepFighting NoProb PigHead Shocked Sinistersmile Slap Social Sweat Tolaugh Watermelon Witty Wow Yeah Yellowdog
提交
评论列表 (有 0 条评论, 88人围观)