Borrow a sentence:
PNG images have good quality. The shadow effect does not have complex edges and is smooth. If you insert a webpage, you can add a lot of colors to the website content! More importantly, the quality of images on the page is improved without increasing the image size. It is very convenient to insert images with irregular borders on over-colored backgrounds with complex backgrounds!
However, at present, the .png image inserted in the transparent background cannot be displayed normally in IE. IE will automatically add a gray background to the image in ". PNG" format.
To address the above problems, IE browser provides filter CSS, which can be used to control the background color. Transparent, fuzzy, and so on.
Based on this idea, you can set the CSS directly and set the CSS path using Js.
Original Style (if the corresponding PNG image is not found, you can try another one at Will)
1. Define CSS directly
<spanstyle="width:512px;height:512px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://online.sccnn.com/icon/1130/pin_001.png',sizingMethod='scale');"></span>
Width and height must be defined here, otherwise they cannot be displayed.
2. Set CSS using JS
<script>function fixPNG(myImage) {var arVersion = navigator.appVersion.split("MSIE");var version = parseFloat(arVersion[1]);if ((version >= 5.5) && (version < 7) && (document.body.filters)){ var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""; var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""; var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' "; var imgStyle = "display:inline-block;" + myImage.style.cssText; var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + myImage.width + "px; height:" + myImage.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"; myImage.outerHTML = strNewHTML;}} </script>
The complete HTML is as follows:
<HTML><HEAD><TITLE> Png Image </TITLE><script>function fixPNG(myImage) {var arVersion = navigator.appVersion.split("MSIE");var version = parseFloat(arVersion[1]);if ((version >= 5.5) && (version < 7) && (document.body.filters)){ var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""; var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""; var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' "; var imgStyle = "display:inline-block;" + myImage.style.cssText; var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + myImage.width + "px; height:" + myImage.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"; myImage.outerHTML = strNewHTML;}} </script></HEAD><BODY><spanstyle="width:512px;height:512px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://online.sccnn.com/icon/1130/pin_001.png',sizingMethod='scale');"></span></BODY></HTML>