CSS 实现个人资料卡

CSS 实现个人资料卡

效果展示

在这里插入图片描述

CSS 知识点

  • CSS 综合知识运用

页面整体布局

<div class="card">
  <div class="imgBox">
    <img src="./bg.jpg" />
  </div>
  <div class="content">
    <div class="details">
      <h2>Alina Smith<br /><span>Senior UX/UI Designer</span></h2>
      <div class="data">
        <h3>342<br /><span>Posts</span></h3>
        <h3>120K<br /><span>Followers</span></h3>
        <h3>285<br /><span>Following</span></h3>
      </div>
      <div class="actionBtn">
        <button>Follow</button>
        <button>Message</button>
      </div>
    </div>
  </div>
</div>

实现个人资料卡基本样式和鼠标悬停样式

.card {
  position: relative;
  width: 350px;
  height: 190px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 35px 80px rgba(0, 0, 0, 0.15);
  transition: 0.5s;
}

.card:hover {
  height: 450px;
}

编写图片个人资料头像样式

.imgBox {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 150px;
  height: 150px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 15px 50px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  transition: 0.5s;
}

.imgBox img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card:hover .imgBox {
  width: 250px;
  height: 250px;
}

编写个人资料卡信息部分基础样式

.card {
  /* 为了方便编写个人资料卡信息部分的样式,我们这里把高度改为450px */
  height: 450px;
}

.card .content {
  position: absolute;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.card .content .details {
  padding: 40px;
  text-align: center;
  width: 100%;
  transition: 0.5s;
}

编写个人资料卡信息数据样式

.card .content .details h2 {
  font-size: 1.25em;
  font-weight: 600;
  color: #555;
  line-height: 1.2em;
}

.card .content .details h2 span {
  font-size: 0.75em;
  font-weight: 500;
  opacity: 0.5;
}

.card .content .details .data {
  display: flex;
  justify-content: space-between;
  margin: 20px 0;
}

.card .content .details .data h3 {
  font-size: 1em;
  color: #555;
  line-height: 1.2em;
  font-weight: 600;
}

.card .content .details .data h3 span {
  font-size: 0.85em;
  font-weight: 400;
  opacity: 0.5;
}

.card .content .details .actionBtn {
  display: flex;
  justify-content: space-between;
}

.card .content .details .actionBtn button {
  padding: 10px 30px;
  border-radius: 5px;
  border: none;
  outline: none;
  font-size: 1em;
  font-weight: 500;
  background: #ff5f95;
  color: #fff;
  cursor: pointer;
}

.card .content .details .actionBtn button:nth-child(2) {
  border: 1px solid #999;
  color: #999;
  background: #fff;
}

编写资料卡信息部分悬停样式

.card {
  /* 把这里的高度改为190px */
  height: 190px;
}

.card .content {
  overflow: hidden;
}

.card .content .details {
  transform: translateY(150px);
}

.card:hover .content .details {
  transform: translateY(0px);
}

完整代码下载

完整代码下载

相关推荐

  1. CSS选择器 个人练习笔记

    2024-06-16 21:12:01       43 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-16 21:12:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-16 21:12:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-16 21:12:01       87 阅读
  4. Python语言-面向对象

    2024-06-16 21:12:01       96 阅读

热门阅读

  1. 【Flask 系统教程 7】数据库使用 SQLAlchemy

    2024-06-16 21:12:01       25 阅读
  2. Dubbo源码解析-mock原理

    2024-06-16 21:12:01       30 阅读
  3. MYSQL in和exists

    2024-06-16 21:12:01       31 阅读
  4. C语言结构体学生

    2024-06-16 21:12:01       28 阅读
  5. c语言连接两个字符串

    2024-06-16 21:12:01       25 阅读