萬盛學電腦網

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

CSS 縮寫屬性速查表:顏色、盒模型、邊框、背景、字體、列表一覽

快速參考表

屬性類別縮寫語法順序/關鍵點預設值補充
顏色#rgb / #rrggbb每兩位相同可縮寫—
Margin/Paddingmargin: T R B L順時針:上右下左;1-4 值均合法0
Borderborder: width style color順序固定;style 必填medium / none / currentColor
Backgroundbackground: color image repeat attachment position可省略;建議寫 background-color 兜底transparent / none / repeat / scroll / 0% 0%
Fontfont: style variant weight size/line-height family**size/line-height 與 family 必填**normal / normal / normal / 1em / normal / 瀏覽器預設字體
Listlist-style: type position image可省略disc / outside / none

常見錯誤避坑

  • font: 14px "Arial"; ❌ 缺 line-height 斜線 → 解析失敗。正確:font: 14px/1.5 "Arial"; 或 font: 14px "Arial";(但 line-height 會重置為 normal)。
  • background: url(img.png) no-repeat; 省略 color → 透明,通常無害但建議顯式寫 background-color。
  • margin: 10px 20px 30px; → 上 10、左右 20、下 30(非上右下左)。

最佳實踐

  1. 團隊統一使用 **多行展開** 開發,**建構時壓縮**為單行。
  2. 針對高頻屬性(margin、padding、border、background、font)建立 Snippet/IDE 代碼片段。
  3. 定期審視 CSS,移除冗餘縮寫(如 border: none 可拆為 border-style: none 避免重置 color/width)。
copyright © 萬盛學電腦網 all rights reserved