HTML&CSS:数据卡片可以这样设计

效果演示

这段 HTML 和 CSS 代码创建了一个实时温度的数据卡片。它使用了 CSS 的渐变、阴影、模糊和动画效果来增强视觉效果。(gif图片不清晰)

HTML

html 复制代码
<div class="outer">
  <div class="dot"></div>
  <div class="card">
    <div class="ray"></div>
    <div class="text">75.23℃</div>
    <div>Hum</div>
    <div class="line topl"></div>
    <div class="line leftl"></div>
    <div class="line bottoml"></div>
    <div class="line rightl"></div>
  </div>
</div>
  • outer: 外层容器,用于包含整个温度计组件。
  • dot: 模拟温度计中的水银滴。
  • card: 温度计的主体部分,显示温度读数。
  • ray: 温度计的光晕效果。
  • text: 显示温度读数,使用 CSS 渐变来创建文字颜色渐变效果。
  • line: 温度计的刻度线。

CSS

css 复制代码
.outer {
  width: 300px;
  height: 250px;
  border-radius: 10px;
  padding: 1px;
  background: radial-gradient(circle 230px at 0% 0%, #ffffff, #0c0d0d);
  position: relative;
}

.dot {
  width: 5px;
  aspect-ratio: 1;
  position: absolute;
  background-color: #fff;
  box-shadow: 0 0 10px #ffffff;
  border-radius: 100px;
  z-index: 2;
  right: 10%;
  top: 10%;
  animation: moveDot 6s linear infinite;
}

@keyframes moveDot {
  0%,
  100% {
    top: 10%;
    right: 10%;
  }
  25% {
    top: 10%;
    right: calc(100% - 35px);
  }
  50% {
    top: calc(100% - 30px);
    right: calc(100% - 35px);
  }
  75% {
    top: calc(100% - 30px);
    right: 10%;
  }
}

.card {
  z-index: 1;
  width: 100%;
  height: 100%;
  border-radius: 9px;
  border: solid 1px #202222;
  background-size: 20px 20px;
  background: radial-gradient(circle 280px at 0% 0%, #444444, #0c0d0d);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-direction: column;
  color: #fff;
}
.ray {
  width: 220px;
  height: 45px;
  border-radius: 100px;
  position: absolute;
  background-color: #c7c7c7;
  opacity: 0.4;
  box-shadow: 0 0 50px #fff;
  filter: blur(10px);
  transform-origin: 10%;
  top: 0%;
  left: 0;
  transform: rotate(40deg);
}

.card .text {
  font-weight: bolder;
  font-size: 4rem;
  background: linear-gradient(45deg, #000000 4%, #fff, #000);
  background-clip: text;
  color: transparent;
}

.line {
  width: 100%;
  height: 1px;
  position: absolute;
  background-color: #2c2c2c;
}
.topl {
  top: 10%;
  background: linear-gradient(90deg, #888888 30%, #1d1f1f 70%);
}
.bottoml {
  bottom: 10%;
}
.leftl {
  left: 10%;
  width: 1px;
  height: 100%;
  background: linear-gradient(180deg, #747474 30%, #222424 70%);
}
.rightl {
  right: 10%;
  width: 1px;
  height: 100%;
}
  • .outer: 定义了温度计外层容器的样式,包括大小、圆角、背景渐变等。
  • .dot: 定义了水银滴的样式,包括大小、位置、背景颜色、阴影和动画。
  • @keyframes moveDot: 定义了水银滴的动画,使其在温度计中移动。
  • .card: 定义了温度计主体的样式,包括大小、圆角、边框、背景渐变和布局。
  • .ray: 定义了温度计光晕的样式,包括大小、位置、背景颜色、模糊效果和旋转。
  • .text 和 .unit: 定义了温度读数的样式,使用 CSS 渐变和 background-clip: text 属性来创建文字颜色渐变效果。
  • .line: 定义了温度计刻度线的样式,包括位置和背景渐变。
相关推荐
张鑫旭1 分钟前
AI时代2025年下半年学的这些Web前端特性有没有用?
前端·ai编程
pinkQQx2 分钟前
H5唤醒APP技术方案入门级介绍
前端
Lefan5 分钟前
UniApp 隐私合规神器!一键搞定应用市场审核难题 - lf-auth 隐私合规助手
前端
Null1556 分钟前
浏览器唤起桌面端应用(进阶篇)
前端·浏览器
吴敬悦6 分钟前
我被 border-image 坑了一天,总算解决了
css
Jing_Rainbow8 分钟前
【Vue-2/Lesson62(2025-12-10)】模块化与 Node.js HTTP 服务器开发详解🧩
前端·vue.js·node.js
风度前端1 小时前
用了都说好的 uniapp 路由框架
前端
冴羽1 小时前
2026 年 Web 前端开发的 8 个趋势!
前端·javascript·vue.js
码银1 小时前
ruoyi的前端(vue)新增的时候给字典设置默认值 但不能正常
前端
fengbizhe2 小时前
bootstrapTable转DataTables,并给有着tfoot的DataTables加滚动条
javascript·bootstrap