Solve the problem that some versions of IE do not support the background-size attribute, iebackground-size

Source: Internet
Author: User

Solve the problem that some versions of IE do not support the background-size attribute, iebackground-size

Background-size is a new property of CSS3. Many browsers now support CSS3. However, some versions of the IE browser are not supported, such as IE8 and IE9. Some CSS 3 attributes are supported, but some are not supported. Here we will take a look at the background-size of CSS3.

Background-size attribute

1. Definition:
Background-size is used to adjust the size of the background image. It is displayed in pixels or percentages. When specified as a percentage, the size is determined by the width, height, and location of the background-origin, you can also use cover and contain to scale images.


2. Syntax:
Background-size: contain | cover | 100px 100px | 50% 100%;

3. parameters:
Background-size: contain; // reduce the image size to adapt to the element (keep the aspect ratio of the pixel );
Background-size: cover; // extend the image to fill the element (keep the aspect ratio of the pixel );
Background-size: 100px 100px; // adjust the image size to the specified size;
Background-size: 50% 100%; // adjust the size of the image to the specified size. The percentage is relative to the size of the contained element.

4. browser compatibility:
Internet Explorer and Internet Explorer are not supported;
Add the private property-moz-background-size in Firefox;
Added private attributes-webkit-background-size support for Safari and Chrome;
Opera does not support the background-size attribute, nor does it support adding its private property-o-background-size.

5. Example:

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%;}

When IE does not support this attribute, you can use a filter to achieve this effect.

The Code is as follows:
<strong>background-image: url('file:///F:/test/images/flashbg.jpg');background-size: cover;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='file:///F:/test/images/flashbg.jpg',  sizingMethod='scale');</strong>

In this way, IE can also achieve the effect of background-size: 100% 100%. Note that the two paths must be the same and are absolute paths.


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.