CSS背景屬性background

來源:互聯網
上載者:User

標籤:

background屬性是所有背景屬性的縮寫:

  以下是這些背景屬性:

  background-color:背景顏色

    你可以通過顏色名稱(red/green/blue)來設定

    也可以用十六進位(#fff/#000/#bcbcbc)

    還可以用到rgb(x,x,x)  x取值(0~255)

  background-position:背景開始位置

    也是三種取值方式,第一種是用方位詞(top/right/bottom/left)組合,如left top

    百分比x%  x%,如0% 0%表示左上方

    用像素表示,如100px 100px

  background-size:背景大小

    你可以通過設定給定長度來調節背景大小,如background-size:100px 80px;

    也可用百分比來設定,注意這裡的百分比說的是背景定位地區,而不是映像的原本大小。如background-size:50% 50%;

  background-repeat:背景重複設定

    no-repeat:不重複

    repeat-x: x(水平)方向上重複

    repeat-y: y(垂直)方向上重複

    repeat:重複

  background-origin:指定background-position屬性的相對位置

    padding-box:背景填充框的相對位置

    border-box:背景邊框的相對位置

    content-box:背景相對內容框的位置

<!doctype html><html><head><style>div{    width:100px;    height:100px;    border:1px solid black;    padding:20px;    margin:20px;    background-image:url("weixin.png");    background-repeat:no-repeat;    background-position:top;    float:left;}#id1{    background-origin:padding-box;}#id2{    background-origin:content-box;}#id3{    background-origin:border-box;}</style></head><body><div id="id1">background-origin:指定background-position屬性的相對位置</div><div id="id2">background-origin:指定background-position屬性的相對位置</div><div id="id3">background-origin:指定background-position屬性的相對位置</div></body></html>

效果:

  background-clip:背景的繪製地區

    一樣有padding-box/border-box/content-box三個值

<!doctype html><html><head><style>div{    width:100px;    height:100px;    border:1px dotted grey;    padding:20px;    margin:20px;    float:left;    background-color:red;    border-width:10px;}#id1{    background-clip:padding-box;}#id2{    background-clip:content-box;}#id3{    background-clip:border-box;}</style></head><body><div id="id1">紅色是背景</div><div id="id2">紅色是背景</div><div id="id3">紅色是背景</div></body></html>

 

效果:

 

  background-attachment:背景是否固定或者隨著頁面滾動

    fixed:固定

    scroll:滾動(預設)

  background-image:背景映像

    url:映像路徑

 

CSS背景屬性background

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.