DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS詳解
CSS語法手冊(五):顏色與背景屬性全解析
編輯:CSS詳解     

顏色與背景是營造網頁視覺氛圍的基礎工具。本文整理 CSS 中與前景色、背景相關的七大屬性,方便隨手查閱。

1. color

設定前景或元素的文字顏色,可用顏色關鍵字或 RGB 值,例如 color: purple;、color: #00ff80;、color: rgb(255,200,100); 或百分比寫法 rgb(75%,0%,0%)。

2. background-color

設定頁面或元素的背景色,可用顏色名稱、RGB 值,或 transparent(透明,沿用頁面的預設背景)。

3. background-image

定義背景圖形,值為 none(不使用)或 url(圖片路徑)。建議同時設定 background-color,作為找不到圖片時的後備底色。

4. background-repeat

控制背景是否重複排列:repeat(水平與垂直皆重複,預設)、repeat-x(水平)、repeat-y(垂直)、no-repeat(不重複)。此屬性通常與 background-image、background-position 搭配使用。

5. background-attachment

指定背景是隨元素一起捲動還是固定不動:scroll(隨元素捲動,預設)或 fixed(固定),需與 background-image 併用。

6. background-position

在空間中定位背景圖,可用長度、百分比或關鍵字。垂直方向為 top / center / bottom,水平方向為 left / center / right。例如 top left、left top 與 0% 0% 都表示圖形從元素框的左上角開始;background-position: 50% 50% 則讓背景置中。

7. background(簡寫)

這是個簡寫屬性,可一次設定上述所有背景屬性:background-attachment、background-color、background-image、background-position 與 background-repeat,讓程式碼更精簡易讀。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved