CSS 屬性名稱其實都是英文單字的直白用語,理解字義之後就不必死背。以下依功能分成七類整理。
· float(浮動):設定元素的浮動,常用 left、right
· width / height(寬/高):不依內容多寡,直接決定盒子尺寸
· clear(清除):清除浮動影響,常用 both、left、right
· margin(外邊距):元素邊框之外的間距,含 margin-top / right / bottom / left
· padding(內邊距):元素邊框之內的留白,含 padding-top / right / bottom / left
· border-width(寬度)、border-color(顏色)、border-style(樣式)
四邊皆可拆成 top / right / bottom / left。顏色若一次給四個值,瀏覽器會依「上、右、下、左」順時針套用。
style 常見值:none(無)、dotted(點線)、dashed(虛線)、solid(實線)、double(雙線)、groove(凹槽)、ridge(脊狀)、inset(內凹)、outset(外凸)。
· font-family(字體)、font-size(大小)、font-weight(粗細)、font-style(字型)、font-variant(小型大寫)
· line-height(行高/行距)
· text-transform(大小寫轉換):capitalize 首字大寫、uppercase 全大寫、lowercase 全小寫、none 不轉
· text-decoration(裝飾線):underline 底線、overline 頂線、line-through 刪除線、blink 閃爍、none 無
· background-color(背景色)、background-image(背景圖)
· background-repeat(平鋪方式):no-repeat、repeat、repeat-x(水平)、repeat-y(垂直)
· background-attachment(是否隨捲動):fixed 固定、scroll 滾動
· background-position(起始位置):left / right / top / bottom / center,或直接給座標值
· word-spacing(單詞間距)、letter-spacing(字母間距)
· vertical-align(垂直對齊):baseline、sub、super、top、text-top、middle、bottom
· text-align(水平對齊):left、right、center、justify
· text-indent(首行縮排)
· white-space(空白處理):normal、pre、nowrap
· position(定位類型):absolute 絕對、relative 相對、static 靜態、fixed 固定
· z-index(Z 軸層級):整數,值越大越上層
· visibility(可見性):visible、hidden、inherit
· overflow(溢出處理):visible、hidden、scroll、auto
· clip(裁剪):rect(top right bottom left)
· 定位四兄弟:left、top、width、height
· list-style-type(項目符號):disc 圓點、circle 空心圓、square 方形、decimal 數字、lower-roman / upper-roman 羅馬數字、lower-alpha / upper-alpha 字母
· list-style-image(自訂項目圖)
· list-style-position(縮排位置):inside、outside
把這些字義記起來,之後看到 list-style-position 或 background-attachment 這類長名稱,大致都能猜出用途。