#RRGGBB → #RGB (當 R=G、G=G、B=B 時)
#000000 → #000
#336699 → #369
#ff0000 → #f00
#cc9966 → #c96
/* 適用所有 型別屬性 */
color, background-color, border-color, outline-color,
text-shadow, box-shadow, caret-color, accent-color,
column-rule-color, text-decoration-color, etc.
適用:`margin`、`padding`、`border-width`、`border-radius`、`outline-width`、`gap`、`grid-gap`、`scroll-padding`、`scroll-margin`
/* 順時針:上 → 右 → 下 → 左 (TRBL = Trouble) */
property: value1; /* 4 邊同值 */
property: value1 value2; /* 上下 | 左右 */
property: value1 value2 value3; /* 上 | 左右 | 下 */
property: value1 value2 value3 value4; /* 上 | 右 | 下 | 左 */
/* 邏輯屬性 (支援 RTL,現代首選) */
margin-block: 1rem 2rem; /* block-start | block-end (上 | 下) */
margin-inline: 1rem 2rem; /* inline-start | inline-end (左 | 右) */
/* 單邊完整:width | style | color (style 必填) */
border: 1px solid #000;
/* 四邊分別 */
border-top: 2px dashed red;
border-right: 1px solid #ccc;
border-bottom: 3px double #333;
border-left: 1px dotted transparent;
/* 子屬性多值 (順時針) */
border-width: 1px 2px 3px 4px;
border-style: solid dashed dotted double;
border-color: red green blue yellow;
/* 圓角 (順時針:左上 右上 右下 左下) */
border-radius: 8px;
border-radius: 8px 16px; /* 左上/右下 | 右上/左下 */
border-radius: 8px 16px 24px; /* 左上 | 右上/左下 | 右下 */
border-radius: 8px 16px 24px 32px; /* 完整四角 */
border-radius: 50%; /* 圓形/橢圓 */
border-radius: 20px / 10px; /* 水平半徑 / 垂直半徑 */
/* 完整順序 (CSS3) */
background:
[color]
[image]
[repeat]
[attachment]
[position]
[/ size]
[origin]
[clip];
/* 現代常用 */
background: url('hero.jpg') no-repeat center / cover;
/* 等價:color=transparent, image=url, repeat=no-repeat,
attachment=scroll, position=center, size=cover,
origin=padding-box, clip=border-box */
/* 多重背景 (逗號分隔,第一層最上) */
background:
url('overlay.png') no-repeat center,
linear-gradient(135deg, #667eea, #764ba2);
/* 必填:font-size | font-family (順序固定,不可亂序) */
font: [style] [variant] [weight] / ;
/* 範例 */
font: italic small-caps bold 1rem/1.5 "Noto Sans", sans-serif;
font: 600 1.25rem/1.3 system-ui;
font: 1rem monospace; /* 最簡 */
/* 系統字體關鍵字 (不可拆分混用) */
font: caption | icon | menu | message-box | small-caption | status-bar;
/* 順序:type | position | image */
list-style: none; /* 最常用:移除符號 */
list-style: disc outside none; /* 預設值 */
list-style: square inside url('bullet.svg'); /* 自訂圖片 + 內側符號 */
/* 子屬性預設 */
list-style-type: disc;
list-style-position: outside;
list-style-image: none;
/* ⚠️ 圖片存在時優先於 type 顯示 */
outline: 2px solid #3b82f6; /* width | style | color */
outline-offset: 4px; /* 獨立屬性,不佔空間 */
transition: property duration timing-function delay;
/* 多屬性逗號分隔 */
transition: opacity 0.2s ease, transform 0.15s ease-out, box-shadow 0.2s;
animation: name duration timing-function delay iteration-count direction fill-mode play-state;
/* 實用簡化 */
animation: fadeIn 0.3s ease-out forwards;
animation: slideUp 0.4s cubic-bezier(0.16,1,0.3,1) 0.1s 1 normal both;
flex: ;
flex: 1; /* 1 1 0% - 平均分配剩餘空間 */
flex: auto; /* 1 1 auto - 內容基準分配 */
flex: none; /* 0 0 auto - 固定尺寸 */
flex: 0 0 300px; /* 固定 300px,不伸縮 */
grid: / ;
grid: "header header" auto
"sidebar main" 1fr
"footer footer" auto
/ 250px 1fr; /* 包含 grid-template-areas + rows + columns */
| 縮寫 | 隱式重置 | 正確做法 |
|---|---|---|
| font | line-height → normal | 明確寫 size/line-height 或分開聲明 |
| background | size → auto, origin → padding-box, clip → border-box | 用斜線語法指定 size |
| border | color → currentColor | 明確指定色彩 |
| margin/padding | 覆蓋所有單邊屬性 | 統一用縮寫或邏輯屬性 |
| flex | basis → 0 (單值時) | 建議寫完整三值 |