CSS3--Background size (background-size)

Source: Internet
Author: User

1, background description

CSS2, Background property:

Writable, detachable
Background: [<background-color>]<Background-image >[,<background-repeat>] [<background-attachment >[,<background-position>]

  = = "Background-color:Red (color name),#FF0000 (binary), RGB (255, 0, 0), RGB (100%, 0%, 0%), HSL (0, 100%, 50%). RGBA (255,0,0,1) is also available in CSS3.

  = = "Background-image: None | | <url>.

  = = "Background-repeat: Repeat | | repeat-x | | repeat-y | | no-repeat.

  = = "Background-attachment: Scroll | | fixed.

(Background-attachment is primarily used to set whether the background image is fixed or scrolled along with the rest of the page, and its default value is scroll, which means that the background picture scrolls with the scroll bar, and the background image is fixed when the value fixed.) )

  = = "Background-position: <percentage> | | <length> | | [Left|center|right] [, Top|center|bottom].

CSS3, the background attribute adds a new   background-size (background size), Background-clip(background clipping), Background-origin(background origin).

  

2, background-size syntax, value

< length > < percentage > | | Cover | | Contain

= = "Auto: default value, keep the original height and width of the background picture; "

= = "Cover: background image enlarged to fit the entire container; (background image distortion)

     (Scene): when the picture is smaller than the container and cannot be implemented using Background-repeat, cover can be used.

  = = "contain: This value is just the opposite of cover, the background image shrinks to fit the entire container; (Background image distortion)

    (Scene): when the background picture is larger than the element container, the background picture needs to be displayed.

  = = "<LENGTH>: set a specific value to change the size of the background image .

  = = "<PERCENTAGE>: hundred points, but any value between 0%?100%, this value can only be applied to the block element , the set percent will use the background picture size according to the width of the element to calculate the percentage.

3, Background-size compatible

  

More compatibility scenarios:

4. Background-size Usage

/*mozilla*/-moz-background-size:auto | |<length>||<percentage>| | | cover | | contain/*webkit*/-webkit-background-size:auto | |<length>||<percentage>| | | cover | | contain/*presto*/-o-background-size:auto | |<length>||<percentage>| | | cover | | contain/*W3C standard */Background-size:auto | |<length>||<percentage>|| Cover | | Contain

There is a filter in IE that is similar to cover: (If you use a filter, Background-size:cover is not supported in IE6.) )

Filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (src= '. /images/background-image.jpg ', sizingmethod= ' scale ');-ms-filter: "Progid:d XImageTransform.Microsoft.AlphaImageLoader (src= '. /images/background-image.jpg ', sizingmethod= ' scale ');

Organized from:(w3cplus) CSS3 background-size

CSS3--Background size (background-size)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.