
本文详解如何使用纯 html 与 css 实现类似 solo.to/linktree 中的经典卡片布局:圆形头像居中悬浮于卡片上方、文字左对齐、右侧带箭头按钮,且整体具备阴影、圆角与响应式美感。
本文详解如何使用纯 html 与 css 实现类似 solo.to/linktree 中的经典卡片布局:圆形头像居中悬浮于卡片上方、文字左对齐、右侧带箭头按钮,且整体具备阴影、圆角与响应式美感。
要实现 Linktree 风格的卡片(如 solo.to 示例图 所示),关键在于视觉层级控制与精确定位,而非依赖 float —— 因为 float 会破坏文档流,难以精准实现头像“悬浮穿透”卡片背景的效果。正确方案是采用 position: absolute 结合 transform 实现头像居中上浮,并通过层叠上下文(z-index 隐式控制)确保头像覆盖卡片顶部区域。
以下是完整、可直接运行的实现方案:
✅ 核心结构说明
- .card:主容器,设定固定尺寸、柔和阴影与浅绿色背景(#eaf5f0);
- .imgBx:绝对定位的圆形头像容器(宽高 150px,border-radius: 20px 呈椭圆感,实际视觉接近圆形),通过 transform: translateX(-50%) 水平居中;
- .content:卡片内容区,采用 Flex 布局居中对齐,内部 .details 左对齐文字,#arrow 按钮右置并赋予独立背景与阴影;
- 头像
使用 object-fit: cover 确保填充不拉伸,border-radius: 5px 与父容器协同形成柔边效果。
? 完整代码(HTML + CSS)
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Linktree 风格卡片</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap" rel="stylesheet"><style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #ebebeb;
font-family: 'Poppins', sans-serif;
padding: 20px;
}
.card {
position: relative;
width: 400px;
height: 200px;
background: #eaf5f0;
border-radius: 5px;
box-shadow: 0 35px 80px rgba(0, 0, 0, 0.15);
overflow: hidden;
}
.imgBx {
position: absolute;
top: -40px; /* 向上偏移,使头像半悬于卡片外 */
left: 50%;
transform: translateX(-50%);
width: 150px;
height: 150px;
background: white;
border-radius: 50%; /* 严格圆形 */
box-shadow: 0 15px 50px rgba(112, 112, 112, 0.35);
z-index: 10;
display: flex;
justify-content: center;
align-items: center;
}
.imgBx img {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 50%;
vertical-align: middle;
}
.content {
position: absolute;
inset: 0;
display: flex;
align-items: center;
padding: 0 24px;
z-index: 1;
}
.details h2 {
font-size: 1.5rem;
font-weight: 600;
color: #2d3748;
line-height: 1.3;
margin-bottom: 4px;
}
.details span {
font-size: 0.95rem;
font-weight: 500;
color: #4a5568;
letter-spacing: 0.2px;
}
#arrow {
background-color: #2d3748;
color: white;
border: none;
width: 40px;
height: 40px;
border-radius: 50%;
font-size: 1.2rem;
font-weight: bold;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
transition: all 0.3s ease;
z-index: 5;
}
#arrow:hover {
background-color: #1a202c;
transform: scale(1.05);
}
/* 响应式优化 */
@media (max-width: 480px) {
.card {
width: 340px;
height: 180px;
}
.imgBx {
width: 130px;
height: 130px;
top: -35px;
}
.details h2 {
font-size: 1.3rem;
}
}
</style><div class="card">
<div class="imgBx">
@@##@@
</div>
<div class="content">
<div class="details">
<h2>Subscribe<br><span>patreon.com</span>
</h2>
</div>
<button id="arrow">→</button>
</div>
</div>
⚠️ 注意事项与优化建议
- 头像定位关键:.imgBx 的 top: -40px 与 transform: translateX(-50%) 共同实现“悬浮居中”,数值需根据卡片高度微调;
- 避免 float:float 会导致脱离文档流,无法精确控制重叠关系,absolute + z-index 是更可控的现代方案;
- 语义化增强:建议为按钮添加 aria-label="Go to Patreon",提升无障碍访问体验;
- 图片加载容错:生产环境应添加 onerror 备用图标或占位符;
- 性能提示:阴影(box-shadow)和 transform 均被 GPU 加速,但大量卡片时建议启用 will-change: transform 或 contain: layout paint。
该方案已在 Chrome、Firefox、Safari 最新版验证,支持移动端缩放,无需 JavaScript 即可实现完整交互与视觉效果,是构建 Linktree 类导航卡片的轻量级、高兼容性范例。

前端入门到VUE实战笔记:立即使用
在学习笔记中,你将探索 前端 的入门与实战技巧!











