| 完整 | 縮寫 | 條件 |
|---|---|---|
| #000000 | #000 | 每兩碼相同 |
| #336699 | #369 | 每兩碼相同 |
| #ff0000 | #f00 | 每兩碼相同 |
| #f2f2f2 | 不可縮寫 | 每兩碼不同 |
| rgb(255,255,255) | #fff / white | 關鍵字/縮寫 |
現代補充:#rgba(4碼)、#rrggbbaa(8碼)支援透明度,如 #0000ff80 = 50% 透明藍。
/* 縮寫 */
border: 2px solid #333;
/* 等效 */
border-width: 2px; border-style: solid; border-color: #333;
/* 單邊 */
border-bottom: 1px dashed #ccc;
border-left: 3px solid #0066cc; /* 常用於側邊標籤 */
/* 四值:上 右 下 左(順時針) */
margin: 10px 20px 30px 40px;
/* 三值:上 右左 下 */
padding: 1rem 2rem 1.5rem;
/* 兩值:上下 左右 */
margin: 0 auto; /* 區塊水平置中經典寫法 */
padding: 1rem 2rem;
/* 單值:四邊同值 */
padding: 16px;
/* ⚠️ 值為 0 可省略單位:margin: 0; */
/* ⚠️ 非 0 值必須帶單位:margin: 10px; */
/* 縮寫順序:color image repeat attachment position/size */
background: #fff url("bg.png") no-repeat fixed center top / cover;
/* 等效完整寫法 */
background-color: #fff;
background-image: url("bg.png");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center top;
background-size: cover;
/* 多重背景(現代) */
background:
url("pattern.png") repeat,
linear-gradient(135deg, #667eea, #764ba2) fixed center / cover;
/* 縮寫順序:style variant weight size/line-height family */
font: italic small-caps bold 1rem/1.5 "Noto Sans TC", sans-serif;
/* 必備最小值:size + family */
font: 1rem/1.5 sans-serif;
/* 等效完整寫法 */
font-style: italic;
font-variant: small-caps;
font-weight: bold;
font-size: 1rem;
line-height: 1.5;
font-family: "Noto Sans TC", sans-serif;
/* 縮寫順序:type position image */
list-style: square inside url("bullet.svg");
/* 等效 */
list-style-type: square;
list-style-position: inside;
list-style-image: url("bullet.svg");
/* 1 值 */ margin: 10px; → 上=右=下=左=10px
/* 2 值 */ margin: 10px 20px; → 上下=10px、左右=20px
/* 3 值 */ margin: 10px 20px 30px; → 上=10、右左=20、下=30
/* 4 值 */ margin: 10px 20px 30px 40px; → 上=10、右=20、下=30、左=40
background: url() 清除 color)font 縮寫缺 font-family 會回退瀏覽器預設字體border 必須包含 style(solid/dashed/dotted 等),否則不顯示margin-inline-start 等)無縮寫形式掌握縮寫後,建議學習 CSS 控制滑鼠游標樣式完整指南,豐富互動回饋細節。