CSS 实现个人资料卡

12 篇文章 0 订阅

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);
}

完整代码下载

完整代码下载

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值