一维布局神器,最适合导航栏、卡片列表、垂直居中。
/* 核心代码 */
.container { display: flex; gap: 14px; }
.flex-nav { display: flex; justify-content: space-between; align-items: center; }
.flex-cards .box { flex: 1 1 140px; } /* 自动换行 + 均分 */
.flex-center { display: flex; justify-content: center; align-items: center; }
二维布局,适合复杂行列结构、响应式卡片墙。
/* 核心代码 */
.grid-3 {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 14px;
}
.grid-responsive {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 12px; /* 屏幕变窄自动减列 */
}
多行省略、渐变文字等常用技巧。
这是一段很长很长的文字,用来演示多行文本省略效果。当文字超过两行时,超出部分会被截断并显示省略号,非常适合用在卡片描述、列表摘要等场景。
/* 核心代码 */
.gradient-text {
background: linear-gradient(135deg, #f43f5e, #8b5cf6);
-webkit-background-clip: text;
color: transparent;
}
.clamp-2 {
display: -webkit-box;
-webkit-line-clamp: 2; /* 限制2行 */
-webkit-box-orient: vertical;
overflow: hidden;
}
渐变背景、backdrop-filter 毛玻璃效果。
/* 核心代码 */
.bg-gradient {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.frosted {
background: rgba(255,255,255,0.25);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
不同形状的 border-radius 与 box-shadow 层次。
/* 核心代码 */
.s-round { border-radius: 16px; }
.s-circle { border-radius: 50%; }
.s-pill { border-radius: 999px; }
.s-shadow { box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
.s-shadow-lg { box-shadow: 0 12px 30px rgba(0,0,0,0.18); }
把鼠标移到下面元素上看效果(transition + :hover)。
/* 核心代码 */
.hover-card {
transition: all 0.25s ease;
}
.hover-card:hover {
transform: translateY(-8px);
box-shadow: 0 12px 32px rgba(0,0,0,0.14);
}
.btn { transition: all 0.2s; }
.btn:hover { transform: translateY(-2px); }
@keyframes 实现淡入、脉冲、加载旋转。
/* 核心代码 */
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.4; }
}
.anim-pulse { animation: pulse 1.5s infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.anim-spin { animation: spin 0.8s linear infinite; }
clamp()、aspect-ratio、color-mix()、filter 等。
/* 核心代码 */
.clamp-font { font-size: clamp(18px, 4vw, 40px); }
.aspect-box { aspect-ratio: 16 / 9; }
.mix-box { background: color-mix(in srgb, var(--primary) 60%, #000); }
.f-blur { filter: blur(3px); }
.f-gray { filter: grayscale(100%); }