速記屬性能將多行相關屬性合併為一行,優點:
/* 四值 */
margin: 10px 20px 30px 40px;
/* 三值:上、左右、下 */
margin: 10px 20px 30px;
/* 兩值:上下、左右 */
margin: 10px 20px;
/* 單值:四邊相同 */
margin: 10px;
/* 統一四邊 */
border: 1px solid #000;
/* 單邊 */
border-top: 2px dashed red;
border-right: 1px solid #ccc;
/* 拆解速記 */
border-width: 1px 2px 3px 4px; /* 上右下左 */
border-style: solid dashed dotted double;
border-color: red green blue black;
font: [style] [variant] [weight] size/line-height family;
font: italic small-caps bold 1.2em/1.5 "Microsoft JhengHei", sans-serif;
⚠️ size/line-height 與 family 為必填,其餘省略即為預設值。
/* 傳統 */
background: #fff url(bg.png) no-repeat center top;
/* 現代(支援多背景、漸層、尺寸、原點、裁切) */
background:
linear-gradient(45deg, #fff, #f0f0f0) padding-box,
url(pattern.png) repeat-x border-box,
#fafafa content-box;
#000000 → #000、#336699 → #369。#010203)不可縮寫。rgb()、hsl()、lab()、color() 等函數,語意更清晰。list-style: square inside url(bullet.png);
/* type position image */
border: 1px solid red 會將 border-image 重置為 none。inherit、initial、unset 等關鍵字時,速記屬性行為較複雜,建議拆解單屬性處理。熟練速記屬性,是寫出精簡、專業 CSS 的基本功。建議列印語法速查表貼在螢幕邊,肌肉記憶自然形成。更多 CSS 核心技巧,請關注本站系列。