HTML&CSS:超好看的数据卡片

这个页面实现了一个温度监测仪表盘,包含两个卡片分别显示室温和环境温度。每个卡片都有独特的颜色主题和动画效果,页面使用了 CSS 渐变和阴影来增强视觉效果。


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

演示效果

HTML&CSS

html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>温度监测数据卡片</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            width: 100%;
            max-width: 1200px;
            text-align: center;
        }

        header {
            margin-bottom: 40px;
            color: white;
        }

        h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            text-shadow: 0 2px 4px rgba(0,0,0,0.3);
        }

        .subtitle {
            font-size: 1.1rem;
            opacity: 0.9;
        }

        .cards-container {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 30px;
        }

        .card {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.25);
            width: 350px;
            padding: 30px;
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        .card:hover {
            transform: translateY(-10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
        }

        .card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 8px;
        }

        .room-temp::before {
            background: linear-gradient(90deg, #3498db, #2ecc71);
        }

        .amb-temp::before {
            background: linear-gradient(90deg, #e74c3c, #f39c12);
        }

        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
        }

        .card-title {
            font-size: 1.5rem;
            font-weight: 600;
            color: #2c3e50;
        }

        .icon {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
        }

        .room-temp .icon {
            background: linear-gradient(135deg, #3498db, #2ecc71);
            color: white;
        }

        .amb-temp .icon {
            background: linear-gradient(135deg, #e74c3c, #f39c12);
            color: white;
        }

        .temperature {
            font-size: 4.5rem;
            font-weight: 700;
            margin: 20px 0;
            position: relative;
            display: inline-block;
        }

        .room-temp .temperature {
            color: #3498db;
        }

        .amb-temp .temperature {
            color: #e74c3c;
        }

        .temperature::after {
            content: '℃';
            font-size: 2rem;
            position: absolute;
            top: 10px;
            right: -30px;
        }

        .timestamp {
            color: #7f8c8d;
            font-size: 1.1rem;
            margin: 15px 0 25px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }

        .thermometer {
            height: 180px;
            width: 40px;
            background: #ecf0f1;
            border-radius: 20px;
            margin: 0 auto 25px;
            position: relative;
            overflow: hidden;
            box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
        }

        .thermometer::before {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 0;
            border-radius: 20px;
            transition: height 1s ease;
        }

        .room-temp .thermometer::before {
            background: linear-gradient(to top, #3498db, #2ecc71);
            height: 45%;
        }

        .amb-temp .thermometer::before {
            background: linear-gradient(to top, #e74c3c, #f39c12);
            height: 65%;
        }

        .thermometer::after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 50%;
            transform: translateX(-50%);
            width: 30px;
            height: 30px;
            border-radius: 50%;
        }

        .room-temp .thermometer::after {
            background: linear-gradient(135deg, #3498db, #2ecc71);
        }

        .amb-temp .thermometer::after {
            background: linear-gradient(135deg, #e74c3c, #f39c12);
        }

        .stats {
            display: flex;
            justify-content: space-between;
            margin-top: 20px;
            padding-top: 20px;
            border-top: 1px solid #ecf0f1;
        }

        .stat {
            text-align: center;
        }

        .stat-value {
            font-size: 1.2rem;
            font-weight: 600;
            margin-bottom: 5px;
        }

        .stat-label {
            font-size: 0.9rem;
            color: #7f8c8d;
        }

        .trend {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            font-size: 1.1rem;
            margin-top: 15px;
        }

        .trend-up {
            color: #e74c3c;
        }

        .trend-down {
            color: #2ecc71;
        }

        footer {
            margin-top: 50px;
            color: rgba(255,255,255,0.7);
            font-size: 0.9rem;
        }

        @media (max-width: 768px) {
            .cards-container {
                flex-direction: column;
                align-items: center;
            }

            h1 {
                font-size: 2rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>温度监测仪表盘</h1>
            <p class="subtitle">实时环境数据监测与可视化</p>
        </header>

        <div class="cards-container">
            <!-- 室温卡片 -->
            <div class="card room-temp">
                <div class="card-header">
                    <h2 class="card-title">Room Temp</h2>
                    <div class="icon">
                        <i class="fas fa-home"></i>
                    </div>
                </div>

                <div class="thermometer"></div>

                <div class="temperature">22.1</div>

                <div class="timestamp">
                    <i class="far fa-clock"></i>
                    <span>2025-06-06 10:05:53</span>
                </div>

                <div class="trend trend-down">
                    <i class="fas fa-arrow-down"></i>
                    <span>较昨日下降 1.2℃</span>
                </div>

                <div class="stats">
                    <div class="stat">
                        <div class="stat-value">20.5℃</div>
                        <div class="stat-label">最低温度</div>
                    </div>
                    <div class="stat">
                        <div class="stat-value">23.8℃</div>
                        <div class="stat-label">最高温度</div>
                    </div>
                    <div class="stat">
                        <div class="stat-value">22.3℃</div>
                        <div class="stat-label">平均温度</div>
                    </div>
                </div>
            </div>

            <!-- 环境温度卡片 -->
            <div class="card amb-temp">
                <div class="card-header">
                    <h2 class="card-title">Amb Temp</h2>
                    <div class="icon">
                        <i class="fas fa-sun"></i>
                    </div>
                </div>

                <div class="thermometer"></div>

                <div class="temperature">35.5</div>

                <div class="timestamp">
                    <i class="far fa-clock"></i>
                    <span>2025-06-06 10:05:53</span>
                </div>

                <div class="trend trend-up">
                    <i class="fas fa-arrow-up"></i>
                    <span>较昨日上升 2.8℃</span>
                </div>

                <div class="stats">
                    <div class="stat">
                        <div class="stat-value">28.2℃</div>
                        <div class="stat-label">最低温度</div>
                    </div>
                    <div class="stat">
                        <div class="stat-value">36.7℃</div>
                        <div class="stat-label">最高温度</div>
                    </div>
                    <div class="stat">
                        <div class="stat-value">33.4℃</div>
                        <div class="stat-label">平均温度</div>
                    </div>
                </div>
            </div>
        </div>

        <footer>
            <p>数据更新时间: 2025-06-06 10:05:53 | 温度监测系统 v2.1</p>
        </footer>
    </div>
</body>
</html>

HTML 结构

  • body:定义了页面的主体内容。
  • container:包含整个页面的内容。
  • header:定义页面的页眉,包含标题和副标题。
  • cards-container:包含两个卡片,分别用于显示室温和环境温度。
  • 每个卡片使用 card 定义,包含温度数据和相关统计信息。
  • footer:定义页面的页脚,包含数据更新时间和系统版本信息。

CSS 关键部分

  • *:设置全局盒模型为 border-box,并重置外边距、内边距和字体。
  • body:设置背景为线性渐变,最小高度为视口高度,使用 Flexbox 布局居中显示内容。
  • .container:定义页面的容器样式,包括宽度、最大宽度和文本对齐方式。
  • header:定义页眉的样式,包括内边距和颜色。
  • h1:定义标题的样式,包括字体大小、外边距和文本阴影。
  • .subtitle:定义副标题的样式,包括字体大小和透明度。
  • .card:定义卡片的样式,包括背景颜色、圆角、阴影、宽度、内边距和过渡效果。
  • .card:hover:定义卡片悬停时的样式,包括变换和阴影效果。
  • .card::before:定义卡片顶部的渐变条样式。
  • .room-temp 和 .amb-temp:分别为室温和环境温度卡片定义不同的颜色主题。
  • .card-header:定义卡片头部的样式,包括布局、对齐方式和外边距。
  • .card-title:定义卡片标题的样式,包括字体大小和颜色。
  • .icon:定义图标的样式,包括大小、圆角、对齐方式和颜色。
  • .temperature:定义温度显示的样式,包括字体大小、字体重量、外边距和位置。
  • .temperature::after:定义温度单位的样式,包括字体大小和位置。
  • .timestamp:定义时间戳的样式,包括颜色、字体大小、外边距和布局。
  • .thermometer:定义温度计的样式,包括高度、宽度、背景颜色、圆角和阴影。
  • .thermometer::before:定义温度计内部的渐变条样式,包括高度和过渡效果。
  • .thermometer::after:定义温度计底部的圆形样式,包括背景颜色和位置。
  • .stats:定义统计信息的样式,包括布局、对齐方式和外边距。
  • .stat:定义单个统计项的样式,包括文本对齐方式。
  • .stat-value 和 .stat-label:分别定义统计值和标签的样式,包括字体大小和颜色。
  • .trend:定义趋势指示器的样式,包括布局、对齐方式、间隙和字体大小。
  • .trend-up 和 .trend-down:分别为上升和下降趋势定义不同的颜色。
  • footer:定义页脚的样式,包括内边距、颜色和字体大小。

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

相关推荐
じ☆ve 清风°4 分钟前
JavaScript 原型与原型链:深入理解 __proto__ 和 prototype 的由来与关系
开发语言·javascript·原型模式
又又呢12 分钟前
前端面试题总结——webpack篇
前端·webpack·node.js
dog shit1 小时前
web第十次课后作业--Mybatis的增删改查
android·前端·mybatis
我有一只臭臭1 小时前
el-tabs 切换时数据不更新的问题
前端·vue.js
七灵微1 小时前
【前端】工具链一本通
前端
Nueuis2 小时前
微信小程序前端面经
前端·微信小程序·小程序
_r0bin_5 小时前
前端面试准备-7
开发语言·前端·javascript·fetch·跨域·class
IT瘾君5 小时前
JavaWeb:前端工程化-Vue
前端·javascript·vue.js
zhang98800005 小时前
JavaScript 核心原理深度解析-不停留于表面的VUE等的使用!
开发语言·javascript·vue.js
potender5 小时前
前端框架Vue
前端·vue.js·前端框架