Background-size: cover and-webkit-background-size,

Source: Internet
Author: User

Background-size: cover and-webkit-background-size,

When using jade and styl to write a mobile phone page and the element is a background image, background-size cover is often used, which means that the background image is filled with the entire element, and ensure the aspect ratio of the background image.

That is, when the image is smaller than the container, and the background-repeat cannot be used to implement the current situation, we can use cover; enlarge the background image to the appropriate container size.

Or set the width and height of the element to the width and height of the background image, and set margin-left to half the width of the element to center the element on the mobile phone screen.


One of the newly added attributes of css3 is background-size: cover. How can this problem be compatible with IE ??

Our solution to this problem is to use img;
Listen to the resize event of the window.
The callback function logic of resize is as follows:
When the window aspect ratio is greater than the image aspect ratio, the image width is set to 100%, and the height is set to auto
When the aspect ratio of a window is smaller than the aspect ratio of an image, the image height is set to 100%, and the width is set to auto.
During dom loaded, call the resize callback function first.

One of the newly added attributes of css3 is background-size: cover. How can this problem be compatible with IE ??

CSS 3 is supported only after ie9, but not before.
 

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.