CSS background-size 屬性詳解

來源:互聯網
上載者:User

標籤:img   文法   縮小   log   大小   私人屬性   尺寸   jpg   web   

css background-size 屬性詳解,background-size 指定背景映像大小,以象素或百分比顯示,當指定為百分比時,大小會由所在地區的寬度、高度以及 background-origin 的位置決定,還可以通過 cover 和 contain 來對圖片進行伸縮。

background-size 屬性

1、定義:

background-size 用來調整背景映像的尺寸大小。

2、文法:

以下為引用內容:
background-size : contain | cover | 100px 100px | 50% 100%;

3、參數:

    background-size:contain; // 縮小圖片來適應元素的尺寸(保持像素的長寬比);
    background-size :cover; // 擴充圖片來填滿元素(保持像素的長寬比);
    background-size :100px 100px; // 調整圖片到指定大小;
    background-size :50% 100%; // 調整圖片到指定大小,百分比相對於包含元素的尺寸。

4、瀏覽器安全色:

    IE 和遨遊不支援;
    Firefox 添加私人屬性 -moz-background-size 支援;
    Safari 和 Chrome 添加私人屬性 -webkit-background-size 支援;
    Opera 不支援 background-size 屬性,添加其私人屬性 -o-background-size 也不支援。

5、樣本:

以下為引用內容:
div{
   background:#00ff00 url(img.jpg) no-repeat;
   background-size:60% 80%;
   -moz-background-size:60% 80%;
   -webkit-background-size:60% 80%;
   -o-background-size:60% 80%;
}

 原文地址:http://blog.sina.com.cn/s/blog_475e4b9b0100vpeb.html

CSS background-size 屬性詳解

相關文章

聯繫我們

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