萬盛學電腦網

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

CSS 屬性完整速查手冊:色彩背景、字型、文字、列表、邊界、定位與其他

色彩與背景

屬性功能值範例
color文字顏色red, #f00, #ff0000, rgb(255,0,0), rgb(100%,0%,0%)
background-color背景顏色同 color 格式
background-image背景圖片url(/bg.jpg)
background-repeat平鋪方式repeat, repeat-x, repeat-y, no-repeat
background-attachment固定/捲動scroll, fixed
background-position起始位置top left, 50% 50%, 10px 20px
background綜合簡寫#ffcc00 url(/bg.jpg) fixed center

字型

屬性功能值範例
font-family字體家族Arial, "Microsoft YaHei", sans-serif
font-style斜體normal, italic, oblique
font-variant小型大寫normal, small-caps
font-weight粗細normal, bold, 100-900
font-size大小12px, 1em, 120%, large
font綜合簡寫italic small-caps bold 12px/1.5 "Arial", sans-serif

文字

屬性功能值範例
letter-spacing字間距2px, 0.1em
text-decoration裝飾線none, underline, overline, line-through
vertical-align垂直對齊baseline, sub, super, top, middle, bottom
text-transform大小寫轉換capitalize, uppercase, lowercase, none
text-align水平對齊left, right, center, justify
text-indent首行縮進2em, 24px
line-height行高1.5, 24px, 150%

列表

屬性功能值範例
list-style-type有序/無序符號disc, circle, square, decimal, lower-roman, none
list-style-image自訂圖片符號url(/bullet.png)
list-style-position符號位置outside, inside
list-style綜合簡寫disc inside, url(/dot.png) outside

邊界、邊框、尺寸

屬性功能值規則
margin外邊距1~4 值:上右下左 / 上、左右、下 / 左右、上下 / 四邊同值
padding內邊距同 margin 規則
border-width邊框寬度同 margin 規則
border-color邊框顏色同 margin 規則
border-style邊框樣式solid, dashed, dotted, double, groove, ridge, inset, outset, none
border綜合簡寫1px solid #ccc(寬度 樣式 顏色)
width / height寬/高auto, 長度值, 百分比

浮動與清除

屬性功能值
float浮動方向left, right, none
clear清除浮動left, right, both, none

其他

屬性功能值
z-index堆疊層級整數(可負),數值大者在上層
visibility可見性visible, hidden, collapse (表格), inherit

使用建議

  • 優先使用簡寫屬性(margin, padding, border, font, background, list-style)減少代碼量。
  • line-height 建議使用無單位數值(倍數),利於繼承縮放。
  • box-sizing: border-box 全域重置,統一盒模型計算。
  • 避免直接使用 visibility: hidden 隱藏互動元素,改用 display: none 或 opacity: 0 配合 pointer-events: none。
copyright © 萬盛學電腦網 all rights reserved