萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> Div CSS 教學

CSS 語法縮寫完整速查手冊

顏色縮寫

#000000 → #000
#336699 → #369
/* 規則:每兩位相同可縮寫為一位 */

盒模型縮寫(margin / padding / border-width)

/* 1 值:四邊同值 */
margin: 1em;

/* 2 值:上下 | 左右 */
margin: 1em 0.5em;

/* 3 值:上 | 左右 | 下 */
margin: 1em 0.5em 2em;

/* 4 值:上 | 右 | 下 | 左(順時針) */
margin: 1em 0.5em 2em 1.5em;

邊框縮寫

border-width: 1px;
border-style: solid;
border-color: #000;
/* 縮寫:順序 寬度 樣式 顏色 */
border: 1px solid #000;

背景縮寫

background-color: #f00;
background-image: url(bg.gif);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 0 0;
/* 縮寫:順序 顏色 圖片 重複 附著 位置 */
background: #f00 url(bg.gif) no-repeat fixed 0 0;

/* 預設值(省略時自動套用) */
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;
/* 順序:style variant weight size/line-height family */

列表縮寫

list-style-type: square;
list-style-position: inside;
list-style-image: url(img.gif);
/* 縮寫 */
list-style: square inside url(img.gif);

實務建議

  • **統一團隊縮寫習慣**,減少認知負擔
  • **避免過度縮寫**導致可讀性下降(如複雜 background 可拆行)
  • **建置工具自動最小化**,原始碼保持可讀即可
copyright © 萬盛學電腦網 all rights reserved