HTML&CSS :动态卡片效果

344 阅读2分钟

这段代码实现了一个带有动态效果的卡片,包含标题、内容和三个彩色图标。


大家复制代码时,可能会因格式转换出现错乱,导致样式失效。建议先少量复制代码进行测试,若未能解决问题,私信我,我会发送完整的压缩包给你。

演示效果

HTML&CSS


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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>公众号关注:前端Hardy</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            background: #212121;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }

        .card {
            width: 190px;
            height: 120px;
            padding: 0.5rem;
            background: rgba(198, 198, 198, 0.34);
            border-radius: 8px;
            backdrop-filter: blur(5px);
            border-bottom: 3px solid rgba(255, 255, 255, 0.440);
            border-left: 2px rgba(255, 255, 255, 0.545) outset;
            box-shadow: -40px 50px 30px rgba(0, 0, 0, 0.280);
            transform: skewX(10deg);
            transition: .4s;
            overflow: hidden;
            color: white;
        }

        .card:hover {
            height: 254px;
            transform: skew(0deg);
        }

        .align {
            padding: 1rem;
            display: flex;
            flex-direction: row;
            gap: 5px;
            align-self: flex-start;
        }

        .red {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background-color: #ff605c;
            box-shadow: -5px 5px 5px rgba(0, 0, 0, 0.280);
        }

        .yellow {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background-color: #ffbd44;
            box-shadow: -5px 5px 5px rgba(0, 0, 0, 0.280);
        }

        .green {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background-color: #00ca4e;
            box-shadow: -5px 5px 5px rgba(0, 0, 0, 0.280);
        }

        .card h1 {
            text-align: center;
            margin: 1.3rem;
            color: rgb(218, 244, 237);
            font-size: 20px;
            text-shadow: -10px 5px 10px rgba(0, 0, 0, 0.573);
        }
    </style>
</head>

<body>
    <div class="card">
        <div class="align">
            <span class="red"></span>
            <span class="yellow"></span>
            <span class="green"></span>
        </div>
        <h1>湖人总冠军</h1>
        <p>
            湖人高歌猛进,夺冠概率已经飙升到了联盟第五,仅次于掘金,再这么打下去,那五个字不得喊出来了?
        </p>
    </div>
</body>

</html>

HTML 结构

  • card:卡片容器,包含整个卡片的内容。
  • align:用于对齐和布局卡片顶部的三个圆形图标。
  • red、yellow、green:分别表示红色、黄色和绿色的圆形图标。
  • h1:卡片标题,显示“湖人总冠军”。
  • p:卡片内容,显示关于湖人队的描述性文字。

CSS 样式

  • body:设置页面背景为深灰色,居中对齐内容,全屏高度。
  • .card:定义卡片的样式,包括大小、背景、边框、阴影、倾斜效果和过渡动画。
  • .card:hover:鼠标悬停时,卡片高度增加,倾斜效果重置为 0 度。
  • .align:定义卡片顶部图标的布局,水平排列,有间距。
  • .red、.yellow、.green:分别定义红色、黄色和绿色圆形图标的样式,包括大小、背景颜色和阴影。
  • .card h1:定义卡片标题的样式,包括字体大小、颜色和阴影效果。

各位互联网搭子,要是这篇文章成功引起了你的注意,别犹豫,关注、点赞、评论、分享走一波,让我们把这份默契延续下去,一起在知识的海洋里乘风破浪!