| 屬性類別 | 展開寫法 | 縮寫寫法 | 值順序規則 |
|---|---|---|---|
| Margin / Padding | margin-top: 5px; margin-right: 10px; margin-bottom: 15px; margin-left: 20px; | margin: 5px 10px 15px 20px; | 1值:四邊同值 2值:上下、左右 3值:上、左右、下 4值:上、右、下、左 (順時針) |
| Border | border-width: 1px; border-style: solid; border-color: #ccc; | border: 1px solid #ccc; | 寬度 樣式 顏色(順序不嚴格,建議固定) |
| Border 单边 | border-top-width: 1px; border-top-style: solid; border-top-color: #ccc; | border-top: 1px solid #ccc; | 同上 |
| Font | font-style: italic; font-variant: small-caps; font-weight: bold; font-size: 1em; line-height: 1.5; font-family: Arial, sans-serif; | font: italic small-caps bold 1em/1.5 Arial, sans-serif; | style variant weight size/line-height family(size/family 必填) |
| Background | background-color: #fff; background-image: url(/bg.png); background-repeat: no-repeat; background-position: center top; background-attachment: fixed; | background: #fff url(/bg.png) no-repeat center top fixed; | color image repeat position attachment(順序不嚴格) |
| Color (HEX) | #FF0000, #00FF00, #0000FF | #F00, #0F0, #00F | 三位數縮寫:各通道雙數字相同時(如 FF→F, 00→0) |
/ * 縮寫前 * /
li {
font-family: Arial, Helvetica, sans-serif;
font-size: 1.2em;
line-height: 1.4em;
padding-top: 5px;
padding-bottom: 10px;
padding-left: 5px;
}
/ * 縮寫後 * /
li {
font: 1.2em/1.4em Arial, Helvetica, sans-serif;
padding: 5px 0 10px 5px; /* 上 右 下左 */
}
/ * 垂直間距相同、水平間距相同 * /
margin: 1rem 2rem; /* 上下 1rem, 左右 2rem */
/ * 上下不同、左右相同 * /
padding: 1rem 2rem 1.5rem; /* 上 1rem, 左右 2rem, 下 1.5rem */
/ * 四角不同 * /
border-radius: 4px 8px 12px 16px; /* 左上、右上、右下、左下 */
/ * 八值語法(水平/垂直半徑分離) * /
border-radius: 4px 8px 12px 16px / 2px 4px 6px 8px;
background: url(/img.jpg) no-repeat center / cover content-box border-box;
/* image repeat position / size origin clip */
#RRGGBB 為標準,三位數 #RGB 僅在三通道皆為雙重複數字時使用(#F00、#0F0、#00F、#FFF、#000、#888 等)。#FF33AA)利於 Gzip 壓縮與程式碼閱讀。rgba() / hsla() / #RRGGBBAA (8 位 HEX, CSS Color Level 4)。熟練掌握 CSS 縮寫屬性,能大幅減少代碼行數、提升閱讀效率、縮小檔案體積。關鍵在於記住值順序規則(順時針)與必填項(font-size/font-family),並建立團隊統一的程式碼風格指南。