Background-size CSS properties [just see, share to everyone]

Source: Internet
Author: User

If asked what makes all men live in fear, the answer is uncertain. No one is revealing, but Curiosity kills the cat. Nine of the 10 women agreed. Advertisers try their best to make us feel inadequate, but will tell us that we can improve. Yes, gentlemen .... Size is important.

What I'm saying is background-size . The properties in CSS background-size allow the programmer to decide how to display the specified elements. MooTools programmer Christoph Pojer used technology on his website background-size to make his avatar "completely covered" on the page--even on the phone--on his browser. Let's take a look at how the magical background-size properties are used.

background-sizeCSS Properties

This background-size property has several predefined values, but you can also use numbers like other size properties:

    • contain: contains, the entire background map is to be contained within the element, there is no beyond the part.
    • cover: Overwrite, background to overwrite all areas of the element, no white space appears.
    • length/percentage: numeric value

Whether you believe it or not, the most interesting part is when its value is length and percentage. Here background-size are a few examples to illustrate several different uses:

/* Base Header Classes */#header {/* Header dimension! */height:350px;/* additional background Properties */background-re  Peat:no-repeat;background-position:center center;/* Some box shadow for good fun */-webkit-box-shadow:rgba (0,0,0,0.20) 0 10px 10px;-moz-box-shadow:rgba (0,0,0,0.20) 0 10px 10px;box-shadow:rgba (0,0,0,0.20) 0 10px 10px; /* Overwrite cover */#header. Flex {/* Size matters */-webkit-background-size:cover;-moz-background-size:cover; Background-size:cover;} /* contains contain */#header. Flex {/* Size matters */-webkit-background-size:contain;-moz-background-size:contain; Background-size:contain;} /* Flex, Fun */#header. Flex {/* Size matters */-webkit-background-size:100% auto;-moz-background-size:100% Auto;backgro und-size:100% Auto;}

Christoph used the last example on its website.

background-sizeThe magic lies in its ability to adjust itself. I used to worry that when the browser window changes, there will be unpredictable changes to the page when a Resize event occurs. But background-size it can adapt to the size of the client browser. background-sizesupported in Firefox, Safari, Google Chrome, Opera, and ie9+.

Do you think this technology is worth it? Will it be used on your page?

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.