十六進位色碼若每兩位相同,可縮寫為 3 碼:
| 完整寫法 | 縮寫 | 說明 |
|---|---|---|
#000000 | #000 | 黑色 |
#336699 | #369 | 藍灰色 |
#FF0000 | #F00 | 紅色 |
#ABCDEF | 不可縮寫 | 每兩位不相同 |
順時針順序:上 → 右 → 下 → 左
| 參數數量 | 語法 | 對應關係 | 範例 |
|---|---|---|---|
| 1 個 | value1 | 四邊皆同 | margin: 10px; |
| 2 個 | value1 value2 | 上下 / 左右 | margin: 10px 20px; |
| 3 個 | value1 value2 value3 | 上 / 左右 / 下 | margin: 10px 20px 30px; |
| 4 個 | value1 value2 value3 value4 | 上 / 右 / 下 / 左 | margin: 10px 20px 30px 40px; |
記憶口訣:「上右下左」順時針 🔄
/* 完整寫法 */
border-width: 1px;
border-style: solid;
border-color: #000;
/* 縮寫 */
border: 1px solid #000;
/* 語法:border: width style color; */
單邊縮寫:border-top: 1px solid #000;
/* 完整寫法 */
background-color: #f00;
background-image: url(bg.gif);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: left top;
/* 縮寫 */
background: #f00 url(bg.gif) no-repeat fixed left top;
/* 語法:background: color image repeat attachment position; */
預設值補充:
| 屬性 | 預設值 |
|---|---|
| color | transparent |
| image | none |
| repeat | repeat |
| attachment | scroll |
| position | 0% 0% |
/* 完整寫法 */
font-style: italic;
font-variant: small-caps;
font-weight: bold;
font-size: 1em;
line-height: 140%;
font-family: "Lucida Grande", sans-serif;
/* 縮寫 - 必須包含 font-size 與 font-family */
font: italic small-caps bold 1em/140% "Lucida Grande", sans-serif;
/* 語法:font: style variant weight size/line-height family; */
⚠️ 必須包含 font-size 和 font-family 兩個必要值
/* 完整寫法 */
list-style-type: square;
list-style-position: inside;
list-style-image: url(bullet.gif);
/* 縮寫 */
list-style: square inside url(bullet.gif);
/* 語法:list-style: type position image; */
移除預設符號:list-style: none;
| 寫法 | 展開結果 |
|---|---|
padding: 10px; | 四邊 10px |
padding: 10px 20px; | 上下 10px、左右 20px |
padding: 10px 20px 30px; | 上 10px、左右 20px、下 30px |
padding: 10px 20px 30px 40px; | 上 10px、右 20px、下 30px、左 40px |
--space-md: 1rem;