本文整理了 CSS 核心屬性,按功能模組分類,列出屬性名稱、用途說明及常用值,方便開發快速查閱。
| 屬性 | 用途 | 常用值 |
|---|---|---|
| font-family | 設定字體族系 | Arial, "Microsoft YaHei", sans-serif 等 |
| font-style | 字體風格 | normal, italic, oblique |
| font-variant | 小型大寫字母 | normal, small-caps |
| font-weight | 字體粗細 | normal, bold, bolder, lighter, 100-900 |
| font-size | 字體大小 | px, em, rem, %, 關鍵字 |
| color | 文字顏色 | 十六進制, rgb(), hsl(), 關鍵字 |
| text-align | 水平對齊 | left, right, center, justify |
| text-decoration | 文字裝飾 | none, underline, overline, line-through |
| text-indent | 首行縮進 | 長度值, % |
| line-height | 行高 | 數字, 長度, %, normal |
| letter-spacing | 字母間距 | 長度值, normal |
| word-spacing | 單詞間距 | 長度值, normal |
| text-transform | 大小寫轉換 | capitalize, uppercase, lowercase, none |
| vertical-align | 垂直對齊 | baseline, top, middle, bottom, sub, super |
| 屬性 | 用途 | 常用值 |
|---|---|---|
| background-color | 背景顏色 | 顏色值, transparent |
| background-image | 背景圖片 | url(), none, gradient |
| background-repeat | 平鋪方式 | repeat, repeat-x, repeat-y, no-repeat |
| background-position | 背景定位 | 關鍵字, %, 長度值 |
| background-attachment | 背景固定/滾動 | scroll, fixed, local |
| background | 簡寫屬性 | 依序: color image repeat attachment position |
| border-width | 邊框寬度 | thin, medium, thick, 長度值 |
| border-style | 邊框樣式 | none, solid, dashed, dotted, double, groove... |
| border-color | 邊框顏色 | 顏色值, transparent |
| border | 邊框簡寫 | width style color |
| border-radius | 圓角 | 長度值, % |
| 屬性 | 用途 | 常用值 |
|---|---|---|
| width / height | 寬度/高度 | auto, 長度值, % |
| margin | 外邊距 | 長度值, %, auto |
| padding | 內邊距 | 長度值, % |
| display | 顯示類型 | block, inline, inline-block, flex, grid, none |
| position | 定位方式 | static, relative, absolute, fixed, sticky |
| top/right/bottom/left | 定位偏移 | 長度值, % |
| float | 浮動 | left, right, none |
| clear | 清除浮動 | left, right, both, none |
| z-index | 堆疊順序 | 整數, auto |
| overflow | 溢出處理 | visible, hidden, scroll, auto |
| box-sizing | 盒模型計算 | content-box, border-box |
| 屬性 | 用途 | 常用值 |
|---|---|---|
| list-style-type | 列表項標記 | disc, circle, square, decimal, none |
| list-style-image | 自定義標記圖片 | url(), none |
| list-style-position | 標記位置 | inside, outside |
| cursor | 滑鼠游標樣式 | pointer, default, text, move, help, wait... |
font, background, margin)減少代碼量。border-box 盒模型(box-sizing: border-box)簡化佈局計算。