用户社交信息交互卡片

效果展示

CSS 知识点

  • CSS 基础知识回顾
  • transition-delay 属性的运用

整体页面布局实现

html 复制代码
<div class="card">
  <div class="user">
    <div class="img_box">
      <img src="bg.jpg" />
    </div>
    <div class="content">
      <h2>
        Someone Famous
        <br />
        <span>Product Designer</span>
      </h2>
    </div>
    <span class="toggle"></span>
  </div>
  <ul class="contact">
    <li style="--clr: #c71610;--i:0">
      <a href="#">
        <div class="icon_box">
          <i class="fa-solid fa-envelope"></i>
        </div>
        <p>someone@email.com</p>
      </a>
    </li>
    <li style="--clr: #171515;--i:1">
      <a href="#">
        <div class="icon_box">
          <i class="fa-brands fa-weixin"></i>
        </div>
        <p>18372876781</p>
      </a>
    </li>
    <li style="--clr: #0a66c2;--i:2">
      <a href="#">
        <div class="icon_box">
          <i class="fa-brands fa-qq"></i>
        </div>
        <p>38572913</p>
      </a>
    </li>
  </ul>
</div>

实现整体用户卡片样式

css 复制代码
.card {
  position: relative;
  height: 100px;
  transition: 0.5s;
  transition-delay: 0.5s;
}

.card .user {
  position: relative;
  width: 400px;
  min-height: 150px;
  background: #2196f3;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 10px;
  border-radius: 10px;
  padding: 60px 40px 30px;
}

实现用户头像样式

css 复制代码
.card .user .img_box {
  position: absolute;
  top: 0;
  transform: translateY(-50%);
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 6px solid #fff;
  overflow: hidden;
  transition: 0.5s;
  z-index: 10;
}

.card .user .img_box img {
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

实现用户信息部分样式

css 复制代码
.card .user .content {
  position: relative;
  text-align: center;
}

.card .user .content h2 {
  font-size: 1.2em;
  line-height: 1.05;
  color: #fff;
}

.card .user .content h2 span {
  font-size: 0.75em;
  font-weight: 400;
}

实现用户社交信息展示的按钮样式

css 复制代码
.card .user .toggle {
  position: absolute;
  bottom: 0;
  width: 120px;
  padding: 5px 15px;
  background: #fff;
  border-radius: 30px;
  transform: translateY(50%);
  border: 6px solid var(--bg);
  text-align: center;
  cursor: pointer;
  font-weight: 500;
  transition: 0.5s;
}

.card .user .toggle::before {
  content: "Hire me";
}

使用 JavaScript 实现按钮交互事件

javascript 复制代码
let toggle = document.querySelector(".toggle");
let card = document.querySelector(".card");

toggle.onclick = () => {
  card.classList.toggle("active");
};

编写社交项的样式

css 复制代码
.card .contact {
  position: relative;
  top: 30px;
  width: 100%;
  height: 0;
  display: flex;
  overflow: hidden;
  flex-direction: column;
  gap: 10px;
  transition: 0.5s;
}

.card .contact li {
  list-style: none;
  width: 100%;
  min-height: 100px;
  background: #fff;
  border-radius: 10px;
  display: flex;
  transition: 0.5s;
  opacity: 0;
  transform: scale(0);
  padding: 10px 30px;
}

/* 剩余样式在完整代码中展示 */

编写卡片激活后的样式

css 复制代码
/* 只是展示部分样式 */

.card.active {
  height: 450px;
  transition-delay: 0;
}

.card.active .user .toggle {
  background: #ff4383;
  color: #fff;
}

.card.active .contact {
  height: 325px;
}

.card.active .contact li {
  opacity: 1;
  transform: scale(1);
  transition-delay: calc(0.25s * var(--i));
}

.card.active .contact:hover li {
  opacity: 0.15;
  filter: blur(2px);
  transition-delay: 0s;
}

.card.active .contact li:hover {
  opacity: 1;
  filter: blur(0px);
}

完整代码下载

完整代码下载

相关推荐
Mike_jia22 分钟前
🎓 OpenMAIC 终极指南:清华开源的多智能体 AI 互动课堂平台
前端
踩着两条虫26 分钟前
告别低代码“黑盒”!VTJ.PRO 2.0:用AI与自由重塑Vue3开发
前端·低代码·ai编程
OpenTiny社区32 分钟前
WebAgent :基于 MCP 协议打造的智能应用“超级路由器”
前端·agent·mcp
dweizhao1 小时前
别再用 Figma 画线框图了,Google 这款免费工具直接出 UI 稿
前端
han_1 小时前
JavaScript设计模式(五):装饰者模式实现与应用
前端·javascript·设计模式
ProgramHelpOa1 小时前
Amazon SDE Intern OA 2026 最新复盘|70分钟两题 Medium-Hard
java·前端·javascript
smchaopiao2 小时前
如何用CSS和JS搞定全屏图片展示
前端·javascript·css
酉鬼女又兒2 小时前
零基础快速入门前端CSS Transform 与动画核心知识点及蓝桥杯 Web 应用开发考点解析(可用于备赛蓝桥杯Web应用开发)
开发语言·前端·css·职场和发展·蓝桥杯·html
山川行2 小时前
Python快速闯关8:内置函数
java·开发语言·前端·笔记·python·学习·visual studio
徐小夕2 小时前
花了一周时间,我们开源了一款PDF编辑SDK,支持在线批注+脱敏
前端·vue.js·github