skip to content
我的博客

CSS 核心入门 · 附录:属性速查与资源

/ 3 min read

布局速查

/* Flex(第 3 章) */
display: flex; flex-direction: column;
justify-content: space-between; /* 主轴 */
align-items: center; /* 交叉轴 */
gap: 1rem; flex: 1; flex: none; flex-wrap: wrap; align-self: end;
/* Grid(第 4 章) */
display: grid;
grid-template-columns: 15rem 1fr; /* 显式列 */
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
grid-template-areas: "head head" "side main"; /* 命名图纸 */
grid-column: 1 / -1; grid-row: span 2;
place-items: center; /* 完美居中 */
/* 定位(第 5 章) */
position: relative; /* 锚点制造者 */
position: absolute; top: -0.5rem; inset-inline-end: 0;
position: sticky; top: 0;
position: fixed; inset-block-start: 0;
z-index: 40; isolation: isolate; /* 层级与隔离 */

盒模型与单位(第 1 章)

box-sizing: border-box;
margin-block: 1.5rem; padding-inline: 1rem; /* 逻辑属性(第 9 章) */
width: min(100% - 2rem, 72rem); margin-inline: auto;
max-width: 65ch; /* 行长 */

层叠与响应式(第 2、6 章)

@layer reset, base, components, utilities;
@media (min-width: 48rem) { /* ... */ }
@container (min-width: 20rem) { /* ... */ } /* container-type 先声明 */
@media (prefers-color-scheme: dark) { /* ... */ }
@media (prefers-reduced-motion: reduce) { /* ... */ }
html { scrollbar-gutter: stable; accent-color: var(--brand); }

排版与颜色(第 7 章)

font-family: system-ui, "PingFang SC", sans-serif;
font-size: clamp(1.8rem, 1.2rem + 2.5vw, 3rem); /* 流体排版(第 9 章) */
line-height: 1.75; letter-spacing: -0.01em;
color: oklch(62% 0.19 258 / 0.8);
color-mix(in oklch, var(--brand) 80%, white);

变量与动效(第 8、9 章)

:root { --bg: oklch(98% 0 0); }
[data-theme="dark"] { --bg: oklch(23.6% 0.005 248); }
color: var(--bg, black); /* 带回退 */
transition: background-color 0.2s ease-out, transform 0.15s ease-out;
transform: translateY(-2px) scale(1.02);
@keyframes spin { to { transform: rotate(360deg); } }
animation: spin 1s linear infinite;

现代特性清单

clamp()/min()/max() · :has() · :user-valid/:user-invalid · @property(变量可过渡)· 逻辑属性全套 · dvh/svh · 容器查询 · color-mix() · @layer · text-wrap: balance/pretty · overscroll-behavior · scroll-behavior: smooth · scroll-margin-block

十章一图

主线 章节 一句话
模型 1 2 一切皆盒子;层叠定胜负
布局 3 4 5 Flex 一维、Grid 二维、定位离流
现代化 6 7 8 9 三层响应式、oklch、GPU 动效、变量与 :has()
工程 10 token 先行、覆盖留窄道、五模型定位问题

资源

站内对照索引