| 屬性 | 作用 | 常用值/技巧 |
|---|---|---|
color | 文本顏色 | currentcolor 繼承父色、oklch() 現代色彩 |
text-align | 水平對齊 | start/end 邏輯屬性適配 RTL |
text-decoration | 下劃線/刪除線 | text-decoration-skip-ink: auto 避開字形 |
text-transform | 大小寫轉換 | uppercase/lowercase/capitalize/full-width |
line-height | 行高 | 無單位倍數 1.5,繼承倍數非計算值 |
letter-spacing | 字符間距 | 0.02em 中文微調、0.1em 英文標題 |
font-family | 字體族 | 系統字體棧、Variable Fonts、font-family: "Name", fallback |
font-size | 字號 | clamp(1rem, 2vw, 2rem) 流體排版 |
font-weight | 字重 | 100-900 或 normal/bold,Variable Fonts 任意值 |
font-style | 斜體 | italic/oblique 15deg (可變斜角) |
font-variant | 字體變體 | small-caps、tabular-nums 數字等寬 |
| 屬性 | 作用 | 現代用法 |
|---|---|---|
background-color | 背景色 | CSS變量、系統顏色、color-mix() |
background-image | 背景圖/漸變 | 多重背景、image-set() 響應式圖片 |
background-size | 背景尺寸 | cover/contain、100% auto、auto 200px |
background-position | 背景位置 | center、right 20px bottom 10px (四值語法) |
border-radius | 圓角 | 8px、50%、8px 4px 12px 2px、50% / 25% 橢圓 |
box-shadow | 陰影 | 0 4px 12px rgba(0,0,0,.1)、多層陰影疊加、inset 內陰影 |
text-shadow | 文本陰影 | 0 1px 2px rgba(0,0,0,.1)、霓虹燈效果疊加多層 |
| 屬性 | 作用 | 關鍵點 |
|---|---|---|
margin | 外邊距 | 垂直塌陷、負margin佈局技巧、margin-inline: auto 居中 |
padding | 內邊距 | 配合 box-sizing: border-box、百分比相對寬度 |
border | 邊框 | 簡寫順序 width/style/color,border-image 圖片邊框 |
float | 浮動 | 僅用於文字環繞,**禁用於佈局** |
clear | 清除浮動 | clear: both、::after{clear:both} clearfix |
position | 定位類型 | static/relative/absolute/fixed/sticky |
top/right/bottom/left/inset | 定位偏移 | inset: 0 替代四個方向、邏輯屬性 inset-block/inline |
::before, ::after {
content: ""; /* 必須,否則不生成 */
display: block; /* 或 inline-block */
/* 裝飾性內容:圖標、底線、遮罩、工具提示箭頭 */
}
:focus-visible { /* 僅鍵盤聚焦顯示輪廓 */
outline: 2px solid var(--color-primary);
outline-offset: 2px;
}
::selection { /* 用戶選中文本樣式 */
background: var(--color-primary);
color: white;
}
::marker { /* 列表標記樣式 */
color: var(--color-primary);
content: "→ ";
}
| 特性 | 屬性/語法 | 應用場景 |
|---|---|---|
| 圓角 | border-radius, border-*-radius | 卡片、按鈕、頭像、模態框 |
| 陰影 | box-shadow, text-shadow, filter: drop-shadow() | 層次感、懸浮狀態、圖標陰影 |
| 多重背景 | background: url(), url(), gradient() | 裝飾層疊、無需額外DOM |
| 背景尺寸 | background-size: cover/contain/auto | 響應式背景圖、Hero區塊 |
| 文本溢出 | text-overflow: ellipsis, line-clamp | 單行/多行文本截斷 |
| Flexbox | display: flex, gap, flex: 1 | 一維佈局、導航、表單、卡片 |
| Grid | display: grid, grid-template-columns, gap | 二維佈局、儀表盤、畫廊、響應式 |
| 變形 | transform: translate/scale/rotate/skew, transform-origin | 動畫、居中、3D效果、視差 |
| 變量 | --var: value, var(--var, fallback) | 主題切換、響應式Token、動態計算 |
| 容器查詢 | container-type: inline-size, @container | 組件級響應式、真正的模塊化佈局 |
| 層疊上下文隔離 | isolation: isolate | 解決 z-index 混亂、混合模式隔離 |
| 錨點定位 | anchor-name, position-anchor, anchor() | Tooltip、Popover、菜單定位 (實驗階段) |
--color-primary、--space-md、--shadow-card等語義化變量.btn、.card、.input、.modal 而非散落寫業務類margin-inline、padding-block、border-inline-startstylelint-config-standard + stylelint-config-recess-order 強制屬性順序與最佳實踐這份速查表涵蓋了現代 CSS 開發 90%+ 的高頻屬性。建議收藏並結合 MDN Web Docs 深入學習每個屬性的邊界情況與瀏覽器支持度,構建自己的「CSS 知識圖譜」。