/* 四值:上 右 下 左(順時針) */
margin: 10px 20px 30px 40px;
/* 三值:上 左右 下 */
margin: 10px 20px 30px;
/* 二值:上下 左右 */
margin: 10px 20px;
/* 一值:四邊相同 */
margin: 10px;
/* 邏輯屬性(現代,支援 RTL) */
margin-block: 10px 20px; /* 上 下 */
margin-inline: 10px 20px; /* 左 右 */
/* 完整:寬度 樣式 顏色 */
border: 1px solid #ccc;
/* 單邊 */
border-top: 2px dashed red;
border-right: 1px solid;
border-bottom: 3px double #000;
border-left: 1px solid;
/* 邏輯屬性 */
border-block: 1px solid;
border-inline: 2px dashed red;
/* 四角同值 */
border-radius: 8px;
/* 四值:左上 右上 右下 左下 */
border-radius: 8px 16px 24px 32px;
/* 八值:水平半徑 / 垂直半徑(橢圓角) */
border-radius: 50% 20% / 30% 40%;
/* 完整順序:color image repeat attachment position / size origin clip */
background: #fff url(bg.png) no-repeat fixed center / cover content-box border-box;
/* 常用精簡 */
background: #f5f5f5 url(bg.jpg) no-repeat center / cover;
background: linear-gradient(45deg, #f00, #0f0) no-repeat;
注意:background-size 必須在 position 後用 / 分隔;origin/clip 同值時只寫一次,不同值則第一個為 origin、第二個為 clip。
/* 必須順序:style variant weight stretch size/line-height family */
font: italic small-caps bold 1.2rem/1.5 "PingFang TC", sans-serif;
/* 最小必要:size/line-height family */
font: 1rem/1.5 system-ui, sans-serif;
line-height 必須緊跟 font-size 並用 / 分隔。font-weight: normal),小心覆蓋繼承值。| 屬性 | 簡寫範例 | 展開 |
|---|---|---|
| list-style | list-style: square inside url(bullet.png); | type position image |
| outline | outline: 2px solid red; | width style color |
| flex | flex: 1 1 300px; | grow shrink basis |
| grid | grid: auto-flow dense / 1fr 2fr; | template-rows / template-columns |
| animation | animation: fade 1s ease-in 0s 2 normal forwards; | name duration timing delay count direction fill-mode |
| transition | transition: all 0.3s ease; | property duration timing delay |
/* HEX 3 位數 */
#abc → #aabbcc
#rgba → #rrggbbaa (8 位數)
/* RGB 現代語法 */
rgb(255 0 0 / 50%)
hsl(120 50% 50% / 0.8)
background: red; 會把 background-image 重置為 none。font: 1rem "Serif" bold; 錯誤(weight 必須在 size 前)。CSS 簡寫是「寫少做多」的藝術。熟記 順時針四值、font 必須順序、background 斜線分隔 size 三大核心規則,配合現代邏輯屬性(margin-block 等),能寫出精簡、可維護、跨語言友善的樣式碼。