CSS100Day(6)-卡片练习和绝对定位圆圈

833 字
4 分钟
CSS100Day(6)-卡片练习和绝对定位圆圈

设计简介#

头像外围圆圈可以使用绝对定位把 widthheight 稍微调大一点,然后 topleft 除以2然后变负数

  • 知识点1:filter: brightness(0.9)可以加深背景,但注意该属性作用整个元素和子元素

效果展示#

头像
Jessica Potter
Visual Artist
523 Posts
1387 Likes
146 Follower

实现代码和步骤#

HTML部分#

<div class="frame">
<div class="container">
<div class="profile">
<div class="image">
<div class="circle-1"></div>
<div class="circle-2"></div>
<img src="./jessica-potter.jpg" alt="头像" width="70" height="70" />
</div>
<div class="name">Jessica Potter</div>
<div class="job">Visual Artist</div>
<div class="actions">
<button class="btn">Follow</button>
<button class="btn">Message</button>
</div>
</div>
<div class="stats">
<div class="box">
<span class="value">523</span>
<span class="parameter">Posts</span>
</div>
<div class="box">
<span class="value">1387</span>
<span class="parameter">Likes</span>
</div>
<div class="box">
<span class="value">146</span>
<span class="parameter">Follower</span>
</div>
</div>
</div>
</div>

CSS部分#

  • 关键1:头像外面两个圈是两个div绝对定位,然后宽度比img元素大一点,然后跳转其top、left为负数,值为宽度差/2
  • 关键2:之前理解错误了,transition是不继承的最好放在元素初始状态上
:root {
--brown: #786450;
font-family: "微软雅黑";
}
.frame {
width: 400px;
height: 400px;
border-radius: 2px;
box-shadow: 1px 2px 10px 0px rgba(0, 0, 0, 0.3);
background: linear-gradient(to top right, #eebe6c 0%, #ca7c4e 100%);
color: var(--brown);
display: grid;
place-content: center;
}
.container {
width: 320px;
height: 299px;
background-color: #fff;
border-radius: 2px;
overflow: hidden;
box-shadow: 10px 10px 15px 0 rgba(0, 0, 0, 0.3);
display: flex;
}
.profile {
display: flex;
flex-direction: column;
justify-content: center;
width: 200px;
height: 320px;
text-align: center;
align-items: center;
.image {
margin: 10px 0;
margin-bottom: 20px;
position: relative;
width: 70px;
height: 70px;
.circle-1 {
width: 76px;
height: 76px;
border-width: 1px;
border-style: solid;
border-color: var(--brown) var(--brown) var(--brown) transparent;
position: absolute;
top: -3px;
left: -3px;
border-radius: 50%;
transition: all 1.5s ease-in-out;
}
.circle-2 {
width: 82px;
height: 82px;
border-width: 1px;
border-style: solid;
border-color: var(--brown) transparent var(--brown) var(--brown);
position: absolute;
top: -6px;
left: -6px;
border-radius: 50%;
transition: all 1.5s ease-in-out;
}
img {
border-radius: 50%;
display: block;
}
&:hover {
cursor: pointer;
.circle-1 {
rotate: 360deg;
}
.circle-2 {
rotate: -360deg;
}
}
}
.name {
font-size: 1rem;
font-weight: 700;
}
.job {
font-size: 0.8rem;
}
.actions {
display: flex;
flex-direction: column;
gap: 10px;
align-items: center;
margin: 25px 0;
.btn {
width: 120px;
height: 30px;
border-radius: 15px;
font-size: 12px;
border: 1px solid var(--brown);
transition: all 0.3s ease-in-out;
color: var(--brown);
background-color: #fff;
&:hover {
background-color: var(--brown);
color: #fff;
}
}
}
}
.stats {
display: flex;
flex-direction: column;
flex: 1;
.box {
box-sizing: border-box;
flex: 1;
text-align: center;
display: grid;
place-content: center;
background: #f5e8df;
transition: all 0.5s ease;
.value {
font-weight: 700;
}
.parameter {
font-size: 0.8rem;
}
&:hover {
filter: brightness(0.9);
cursor: pointer;
}
}
}
分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接

评论区

图片
犟哟
Hello, I'm Juyial.
公告
欢迎来到我的博客,在这里可以一起进步,一起学习!2026年起航!
分类
站点统计
文章
20
分类
1
标签
3
总字数
37,015
运行时长
0
最后活动
0 天前

目录