這篇文章整理了 Web 開發中經常使用的 CSS 樣式屬性,幫助初學者快速掌握基本設定方式。
width 與 height 用於設定元素的寬度與高度。
a. background-color:背景顏色。
b. background-image:url():背景圖片。
c. background-repeat:可為 no-repeat、repeat-x、repeat-y。
d. background-position:規範順序為 x y;除了座標數值,x 可取 left/center/right,y 可取 top/center/bottom。
e. background-attachment:設為 fixed 可讓背景固定不動。
a. border-width:可分別設定 border-top/right/bottom/left-width。
b. border-style:值有 solid、dashed、dotted,可分別設定各邊。
c. border-color:可分別設定各邊顏色。
a. font-size:字體大小。
b. font-weight:字體粗細。
c. font-style:字體樣式(如斜體)。
d. line-height:行高。
e. font-family:字體家族。
f. color:文字顏色。
g. text-indent:首行縮排,1em 約等於一個字符寬度。
h. text-align:可為 left/center/right。
i. text-decoration:文字裝飾,underline 為下劃線、line-through 為刪除線、overline 為上劃線、none 為無。
j. letter-spacing:字母間距。
k. word-spacing:單詞間距。
padding 為內邊距(內容與邊框之間的距離),margin 為外邊距(元素與其他元素之間的距離)。兩者都是版面配置中調整間距的核心屬性。