CSS3關於background-size屬性的詳細介紹

來源:互聯網
上載者:User
我們知道,在CSS3裡有一項很重要的屬性,bachground-size屬性,它的作用就是定義背景圖片的大小,值有5種,auto , 像素值 ,百分比 , cover , contain。今天就教大家如何使用bachground-size屬性。

background-size:auto,預設值,以圖片自身大小填充元素,根據元素大小來調節自身比例,不會讓圖片變形。

CSS3關於background-size屬性

1.

<!DOCTYPE html><html><head><meta charset="utf-8"><title>background-size屬性</title><style type="text/css">div{width:300px;height:150px;border:1px solid black;background:url("photo.jpg") no-repeat;}</style></head><body><div></div></body></html>

2.背景圖片本身大小—width:200px ,height:133px ,上述代碼的如下:

像素值,比如 30px 50px,分別表示width height

CSS3關於background-size屬性

<!DOCTYPE html><html><head><meta charset="utf-8"><title>background-size屬性</title><style type="text/css">div{width:300px;height:150px;border:1px solid black;background:url("photo.jpg") no-repeat;background-size:250px 100px;}</style></head><body><div></div></body></html>


相信看了這些案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

相關閱讀:

Css3中transform屬性的使用教程

Css3中的border-image屬性詳細介紹

前端項目裡裡定位幾種方式

相關文章

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.