css中background(背景) 屬性的特點介紹

來源:互聯網
上載者:User
本篇文章給大家帶來的內容是關於css中background(背景) 屬性的特點介紹,有一定的參考價值,有需要的朋友可以參考一下,希望對你有所協助。

簡寫順序:color-image-repeat-attachment-position

eg:body{background:#ffffff url('img.png') no-repeat right top}

下來按順序介紹每個屬性特點:

一、background-color:red;#ffffff;rgb(255,255,255);

三種顏色表示方法,分別是顏色名,十六進位和RGB;可以為所有元素設定背景色;預設透明。

二、background-image:url(‘img.jpg’)

圖片地址可以是相對路徑也可以是絕對路徑;預設平鋪重複顯示;

三、background-repeat:repeat-x;repeat-y;no-repeat;

預設平鋪重複顯示;

四、background-attachment:scroll;fixed;local;inherit;

background-attachment的意思是指背景映像是否固定或者隨著頁面的其餘部分滾動;預設scroll;

scroll是指背景圖片隨著頁面其餘部分滾動;fixed為固定;inherit是從父元素繼承;local是隨滾動元素滾動。

五、background-position:bottom center;top;66% 33%;50px 100px;

4種標記法:一是top,left,bottom,right,center組合;二是一個值,系統預設為center;三是百分比;四是直接寫像素。

後兩種精確度高。

六、background-clip:border-box;padding-box;content-box;規定背景圖的繪製地區。

七、background-origin:border-box;padding-box;content-box;規定背景圖的定位地區。

注意:如果背景映像background-attachment是“固定”,這個屬性沒有任何效果。

八、background-size:auto(預設);length(兩個值,一個寬一個高,一個值的話預設第二個是auto);percentage(賦值原理同length);cover(此時會保持映像的縱橫比並將映像縮放成將完全覆蓋背景定位地區的最小大小);contain(此時保持映像的縱橫比並將映像縮放成將適合背景定位地區的最小大小);

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.