背景(background)是css中一個重要的的部分,也是需要知道的css的基礎知識之一。這篇文章將會涉及css背景(background)的基本用法,包括諸如 background-attachment 等的屬性,也會介紹一些有關背景(background)的常用技巧,以及 css3 中的 背景(background)(包含4個新的背景(background)屬性)。
css2 中的背景(background)
概述
CSS2 中有5個主要的背景(background)屬性,它們是:
* background-color: 指定填充背景的顏色。
* background-image: 引用圖片作為背景。
* background-position: 指定元素背景圖片的位置。
* background-repeat: 決定是否重復背景圖片。
* background-attachment: 決定背景圖是否隨頁面滾動。
這些屬性可以全部合并為一個縮寫屬性: background。需要注意的一個要點是背景占據元素的所有內容區域,包括 padding 和 border,但是不包括元素的 margin。它在 Firefox, Safari ,Opera 以及 IE8 中工作正常,但是 IE6 和 IE7 中,background 沒把 border 計算在內。
基本屬性
背景色(background-color)
background-color 屬性用純色來填充背景。有許多方式指定這個顏色,以下方式都得到相同的結果。
新聞熱點
疑難解答