(In IE6) png transparent Problem Analysis and Solution

Source: Internet
Author: User
Tags transparent image

 

In front-end web development, background or image transparency is often required.

First, we are currently facing the following situations:
1. In common browsers such as ie7 +, firefox, safari, and opera, it is no problem to directly use transparent png, but it cannot be transparent in ie6.

2. ie6's current regular share is still large. We must consider the compatibility with ie6.

Solution:
1. Use gif instead. all browsers can be transparent, but the effect is poor and there are edges. This can be used when the image pixels are relatively simple and the quality requirement is not very high.

2. png is used, but additional processing is required under ie.

3. You need to download microsoft's ie6 upgrade package, but you cannot require every user to upgrade it. Therefore, this method is not considered here.

Png Image transparency Solution

1. Upload a small transparent image transparent.gif.
2.
. Pngfix {
Azimuth: expression (
This.png Set? This.png Set = true :( this. nodeName = "IMG" & this.src.toLowerCase().indexOf('.png ')>-1? (This. runtimeStyle. backgroundImage = "none ",
This. runtimeStyle. filter = "progid: DXImageTransform. Microsoft. AlphaImageLoader (src = '" + this. src + "', sizingMethod = 'image ')",
This. src = "transparent.gif") :( this. origBg = this. origBg? This. origBg: this. currentStyle. backgroundImage. toString (). replace ('url ("',''). replace ('")',''),
This. runtimeStyle. filter = "progid: DXImageTransform. Microsoft. AlphaImageLoader (src = '" + this. origBg + "', sizingMethod = 'crop ')",
This. runtimeStyle. backgroundImage = "none" available, this.png Set = true );
}

Then add the style to the img label.

Png background transparency Solution
. Pngbackground {
Background: url(your.png );
_ Background: none;
_ Filter: progid: dximagetransform.microsoft.alphaimageloader(src+'your.png ', sizingMethod = 'Scale ');
}

Note: When _ is added before the attribute, It is parsed only under ie6.

So far, we have basically solved the problem of png transparency under ie6, but it seems that things are not so smooth. Soon we can find that when png is used as a transparent background, in this case, all the events added above, such as onmouseover and onclick, are ineffective. This is also a feature of the filter, at this time, we need to set the position of this element to relative to solve the problem, that is:
. Pngbackground {
Position: relative;
Background: url(your.png );
_ Background: none;
_ Filter: progid: dximagetransform.microsoft.alphaimageloader(src+'your.png ', sizingMethod = 'Scale ');
}

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.