萬盛學電腦網

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

CSS 屬性完整參考手冊:顏色、字體、文字、列表、邊框與佈局核心屬性詳解

顏色與背景體系

顏色表示法

  • 關鍵字:red
  • 十六進制:#f00 / #ff0000
  • RGB 函數:rgb(255,0,0) / rgb(100%,0%,0%)

背景屬性矩陣

屬性作用典型值
background-color背景顏色同上色值
background-image背景圖片url(/path/img.png)
background-repeat平鋪方式repeat-x、no-repeat
background-attachment滾動行為scroll、fixed
background-position起始位置center top、50px 10px、20% 50%
background綜合簡寫#ffcc00 url(/bg.jpg) fixed center

字體體系

核心屬性

  • font-family:字體族列表,備選機制 "Microsoft JhengHei", "PingFang TC", sans-serif
  • font-style:normal、italic、oblique
  • font-variant:normal、small-caps(英文小型大寫)
  • font-weight:normal/bold 或 100-900 數值
  • font-size:絕對(xx-large)、相對(larger)、長度(16px、1.2rem)、百分比
  • font:綜合簡寫,順序 style variant weight size/line-height family

文字排版體系

屬性功能關鍵值
letter-spacing字符間距0.1em
text-decoration修飾線underline、line-through
vertical-align垂直對齊baseline、middle、sub/super
text-transform大小寫轉換uppercase、capitalize
text-align水平對齊left、center、justify
text-indent首行縮進2em、-9999px(隱藏文字)
line-height行高1.5、24px、150%

列表體系

  • list-style-type:有序 decimal/lower-roman,無序 disc/circle/square
  • list-style-image:自定義圖標 url(/icon.png)
  • list-style-position:outside(預設)、inside
  • list-style:綜合簡寫

盒模型與佈局核心

邊距/內距/邊框簡寫規律

均遵循順時針順序:上 → 右 → 下 → 左。值數量對應規則:

  • 1 值:四邊同值
  • 2 值:上下、左右
  • 3 值:上、左右、下
  • 4 值:上、右、下、左

關鍵屬性速查

屬性說明
border綜合設定寬度、樣式、顏色:1px solid #333
width/height元素盒尺寸
float浮動佈局:left/right/none
clear清除浮動:left/right/both
z-index疊放層級,整數可負
visibilityvisible/hidden/collapse

總結

熟練掌握上述核心屬性及其簡寫規則,是高效編寫、維護 CSS 的基礎。建議建立個人常用片段庫,結合現代 CSS 變量(Custom Properties)實現設計系統級的樣式管理。

copyright © 萬盛學電腦網 all rights reserved