跟css背景有關的屬性

來源:互聯網
上載者:User

標籤:top   log   忘記   區別   start   知識點   20px   映像   repeat   

 

印象中css控制背景的就一個background,但是background是一個複合屬性

它包括:

  • background-color:背景顏色,css支援的顏色表示方法,都可以用
  • background-image:背景圖片(url)
  • background-repeat:背景是否重複(repeat、no-repeat、repeat-x、repeat-y)
  • background-position:背景定位(關鍵字、百分比、像素)
  • background-size:背景大小
  • background-origin:背景的定位地區
  • background-clip:背景繪製地區
  • background-attachment:規定背景映像是否固定或者隨著頁面的其餘部分滾動

除了這些,多背景、漸層、遮罩,我也把他們歸到背景裡吧。

一個個看看吧-0-。

開頭說了,我很長時間都以為背景就是background這一個單詞的玩意。因為我總是寫成:

1 .div{2     background: #000 url("1.jpg") no-repeat left center;/*顏色、圖片、是否平鋪、定位*/3 }

 

背景的定位地區(background-origin):值是關鍵字
 1     .div{ 2         width: 400px; 3         height: 200px; 4  5         padding: 20px; 6         border:10px solid rgba(255,255,255,.2); 7  8         background: #000 url("1.jpg") no-repeat; 9         background-origin:border-box;10         /*background-origin:padding-box;*/11         /*background-origin:content-box;*/12     }

 

  • border-box
  • padding-box
  • content-box

以上就是background-origin的效果,但是貌似好像跟我想要的有那麼點區別,底邊跟右側在padding、content的時候還是有背景圖,而且啊好像對背景顏色(#000)沒起作用

背景的定位地區(background-origin):值是關鍵字
 1 .div{ 2     width: 400px; 3     height: 200px; 4  5     padding: 20px; 6     border:10px solid rgba(0,0,0,.1); 7  8     background:#000 url("1.jpg") no-repeat; 9     /*background-clip:border-box;*/10     /*background-clip:padding-box;*/11     background-clip:content-box;12 }

 

  • border-box:

     

  • padding-box:

     

  • content-box:

     

以上就是background-clip的效果,感覺比background-origin好那麼點,哈。

多個背景圖

以前在一個容器(div)裡,實現多層背景,只能在容器裡多寫幾個子項目,然後在把子項目定位。簡單點讓設計給出賬圖,直接糊上去完事(我經常乾的事,哈哈)。

現在實現上邊的效果,只要一個div就可以了。

 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4     <meta charset="UTF-8"> 5     <title>Title</title> 6     <style> 7         .div{ 8             width: 240px; 9             height: 150px;10             border:1px solid #000;11             12             background: url("1.jpg") no-repeat left top,13                         url("2.jpg") no-repeat left bottom,14                         url("3.jpg") no-repeat right bottom;15             background-size:100px auto, 100px auto, 100px auto;16         }17     </style>18 </head>19 <body>20 <div class="div"></div>21 </body>22 </html>
多個背景

 

 

 

 

 

說實話,看完這些知識點,真的不想再重新寫一遍。感覺忘記在查手冊、百度、Google一下就好了。

不過心裡邊總是還有點糾結吧。

在堅持堅持吧!!!還有漸層沒有寫

 

跟css背景有關的屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.