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: 定义了温度计刻度线的样式,包括位置和背景渐变。
相关推荐
忧郁的蛋~11 分钟前
开发vue项目所需要安装的依赖包
前端·javascript·vue.js
服部14 分钟前
如何查看指定作者在所有分支的提交记录
前端·git·github
JohnYan14 分钟前
工作笔记 - ASN.1密钥结构和编码研究
javascript·后端·安全
前端付豪22 分钟前
1、为什么浏览器要有渲染流程? ——带你一口气吃透 Critical Rendering Path
前端·后端·浏览器
前端付豪25 分钟前
3、Node.js异步编程彻底吃透
前端·后端·node.js
Bob999828 分钟前
Amlogic S905L3系列盒子 ROM DIY相关
java·javascript·数据仓库·vscode·eclipse·tomcat·vim
孤鸿玉30 分钟前
[Flutter小试牛刀] 低配版signals,添加局部刷新
前端·flutter
亦黑迷失31 分钟前
轻量级 Express 服务器:用 Pug 模板引擎实现动态参数传递
前端·javascript·后端
吃瓜群众i1 小时前
理解Javascript闭包
前端·javascript