


Use Js or CSS filters to achieve the translucent effect of PNG images in IE6 IE6PNG properly_html/css_WEB-ITnose
Jun 24, 2016 am 11:56 AM
The following will introduce several solutions to PNG images being opaque in IE6
1. Use your own PNG and let IE6 go by itself
When making a PNG image first, save it as a GIF image, because IE6 supports transparency of GIF images, and then define it in css
.pngtest{ background:url(mark.png); _background:url(mark.gif);}
Advantages: Convenient, fast, easy to use Super simple
Disadvantages: This method is more effective for PNG images that are only partially transparent, but if the image is semi-transparent, this method cannot be achieved
Another extension of this method A solution: Use PS or other image editing tools to save the png image in 8-bit format, so that IE6 supports transparency
2. Use CSS filter to make the PNG image translucent
.pngwrap{ padding:80px; background:green;}.pngtest{ width:165px; height:50px; overflow:hidden; text-indent:-9999em;background:url(http://www.qmtx3.com/data/mark/mark.png) no-repeat;_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.qmtx3.com/data/mark/mark.png' sizingMethod='scale' enabled=true);}
Testing IE6 to use CSS filters to solve the transparency problem of PNG images
Code description: _The prefixed css attribute can only be recognized by IE6, as for why it needs to be added_ background:none;, the reason is that the layer depth of the background image defined earlier (can be understood as the z-index of the attribute) is higher than that of the filter, which will block the image defined by the filter, so the background of IE6 should be set to none here. , PS: The image path in the filter can be a remote image path or a relative path. If a relative path is used, it should be a path relative to the page rather than CSS
Advantages: No JS patch is required, pictures The maintenance cost is low, because it is just a png image
Disadvantages: the image defined by the filter does not support the background-position:; (positioning) background-repeat:; (tile) attribute, so CSS Sprite technology cannot be used. And this method cannot be applied to the img tag. When applied to the link a tag, sometimes the link cannot be clicked. In this case, the a tag needs to be defined position:relative
3. HTC plug-in PNG image IE6 Let me go
Starting from version 5.5, Internet Explorer (IE) begins to support the concept of Web behavior. These behaviors are described by script files with the suffix .htc, which define a set of methods and attributes that programmers can apply to almost any element on the HTML page.
For detailed htc file introduction, please steadily
Download the IE6 browser PNG image transparent HTC plug-in
Copy the iepngfix.htc and blank.gif files to your website directory (copy blank. gif, iepngfix.htc, iepngfix_tilebg.js (this file is essential to support position and repeat attributes) to a certain location;)
definition will be defined using the tag of the PNG image, as shown in the following css Style
img,div{behavior:url(iepngfix.htc);}
Modify IEPNGFix.blankImg = 'images/blank.gif' in iepngfix.htc; the path is your image path
Let the IE6 browser load the JS file
<!--[if IE 6]><script type="text/javascript" src="../js/iepngfix_tilebg.js"></script><![endif]-->
Advantages: After configuring this, it will be very convenient to use the entire site. Once configured, it will be used for life.
Disadvantages: When configuring the relative method, the website will have three more files, it does not support pseudo-classes such as element hover, and CSS Sprite technology cannot be used. When the page is loaded, you will still see that the transparent area of ??the png image is gray
4. CSS version JS solution
This method also requires a transparent blank.gif image, which is included in the third method compressed package. It is not provided separately here. Define the CSS style
img{_azimuth:expression(this.pngSet?this.pngSet=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 = "blank.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")),this.pngSet=true);}
Code description: this.src = "blank.gif" The path is also relative to the page file, not the CSS file
Advantages: Method Relatively simple
Disadvantages: Need to add a transparent image blank.gif, only supports the img tag and does not support PNG background images set by elements. It does not support element hover and other pseudo-classes. It will also appear gray when it is first loaded
5. Original javascript solution
There are many plug-ins for javascript to solve the opacity of IE6 PNG images. I chose to use it based on my personal preference
Plug-in 1 : iepngfix
Download IE6 browser PNG image transparent iepngfix plug-in
Let IE6 browser load JS files
<!--[if IE 6]><script type="text/javascript" src="js/iepngfix.js"></script><![endif]-->
Plug-in 2: DD_belatedPNG
This plug-in should be regarded as a real plug-in, and its usage is very plug-in-like
Download the IE6 browser PNG picture transparent DD_belatedPNG plug-in
Backup of this blog: DD_belatedPNG.js
<!--[if IE 6]><script type="text/javascript" src="js/DD_belatedPNG.js"></script><![endif]-->
Usage:
DD_belatedPNG.fix(".pngtest,#pngtest,.pngtest img,.pngtest:hover");
<!--[if IE 6]> <script type="text/javascript" src="js/DD_belatedPNG.js"></script> <script language="javascript" type="text/javascript"> window.onload = function(){ DD_belatedPNG.fix("*"); } </script><![endif]-->
The fix() parameter is passed to transparent elements or sub-elements. This method is basically the same as jQuery select $, except that it is separated between multiple elements. It is "," and jQ uses spaces. For more convenience, you can add
at the end of the file. The solution for w3cfuns is to add id or class to each tag that uses png, and then write it as
window.onload = function(){ DD_belatedPNG.fix(".pngFix,.pngFix:hover");}
In this way, add class="pngFix xx bbb" to the elements that need to be transparent on the page. As long as the class contains pngFix, it will be fine
Advantages: Supports img tag, CSS Sprite, background, tile, pseudo-class, no need to configure anything, you can use it by introducing JS, like it
缺點:加載初期PNG圖片會出現(xiàn)灰色
插件三:EvPng
該插件使用方法包括優(yōu)缺點都跟DD_belatedPNG相同,不再詳述
下載IE6瀏覽器PNG圖片透明EvPng插件
<!--[if IE 6]> <script type="text/javascript" src="js/EvPng.js"></script> <script language="javascript" type="text/javascript"> window.onload = function(){ EvPNG.fix("*"); } </script><![endif]-->
插件四:jQueryPngFix插件
下載IE6瀏覽器PNG圖片透明jQueryPngFix插件
博客備份:JqueryPngFix
修改pngfix.js文件中blankgif: 'images/blank.gif'透明GIF圖片路徑為相對頁面路徑
讓IE6瀏覽器加載JS文件
<!--[if IE 6]><script type="text/javascript" src="js/pngfix.js"></script><![endif]-->
?
優(yōu)點:支持img、css背景
缺點:需要jQuery庫支持,不支持CSS Sprite、平鋪、偽類,加載初期會出現(xiàn)灰色
有了這種方法htc的解決方案,顯得多于了,不過這里介紹的htc解決IE6 PNG透明問題只是htc功能的冰山一角,htc在其他方面的應(yīng)用遠(yuǎn)遠(yuǎn)比這強(qiáng)大的多
參考:
http://www.w3cfuns.com/forum.php?mod=viewthread&tid=297
http://www.cnblogs.com/rock506/archive/2010/11/30/1892067.html
http://www.xuanfengge.com/ie6-png-transparency-solution.html

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The key to keep up with HTML standards and best practices is to do it intentionally rather than follow it blindly. First, follow the summary or update logs of official sources such as WHATWG and W3C, understand new tags (such as) and attributes, and use them as references to solve difficult problems; second, subscribe to trusted web development newsletters and blogs, spend 10-15 minutes a week to browse updates, focus on actual use cases rather than just collecting articles; second, use developer tools and linters such as HTMLHint to optimize the code structure through instant feedback; finally, interact with the developer community, share experiences and learn other people's practical skills, so as to continuously improve HTML skills.

The reason for using tags is to improve the semantic structure and accessibility of web pages, make it easier for screen readers and search engines to understand page content, and allow users to quickly jump to core content. Here are the key points: 1. Each page should contain only one element; 2. It should not include content that is repeated across pages (such as sidebars or footers); 3. It can be used in conjunction with ARIA properties to enhance accessibility. Usually located after and before, it is used to wrap unique page content, such as articles, forms or product details, and should be avoided in, or in; to improve accessibility, aria-labeledby or aria-label can be used to clearly identify parts.

To create an HTML checkbox, use the type attribute to set the element of the checkbox. 1. The basic structure includes id, name and label tags to ensure that clicking text can switch options; 2. Multiple related check boxes should use the same name but different values, and wrap them with fieldset to improve accessibility; 3. Hide native controls when customizing styles and use CSS to design alternative elements while maintaining the complete functions; 4. Ensure availability, pair labels, support keyboard navigation, and avoid relying on only visual prompts. The above steps can help developers correctly implement checkbox components that have both functional and aesthetics.

To reduce the size of HTML files, you need to clean up redundant code, compress content, and optimize structure. 1. Delete unused tags, comments and extra blanks to reduce volume; 2. Move inline CSS and JavaScript to external files and merge multiple scripts or style blocks; 3. Simplify label syntax without affecting parsing, such as omitting optional closed tags or using short attributes; 4. After cleaning, enable server-side compression technologies such as Gzip or Brotli to further reduce the transmission volume. These steps can significantly improve page loading performance without sacrificing functionality.

To create a basic HTML document, you first need to understand its basic structure and write code in a standard format. 1. Use the declaration document type at the beginning; 2. Use the tag to wrap the entire content; 3. Include and two main parts in it, which are used to store metadata such as titles, style sheet links, etc., and include user-visible content such as titles, paragraphs, pictures and links; 4. Save the file in .html format and open the viewing effect in the browser; 5. Then you can gradually add more elements to enrich the page content. Follow these steps to quickly build a basic web page.

HTMLhasevolvedsignificantlysinceitscreationtomeetthegrowingdemandsofwebdevelopersandusers.Initiallyasimplemarkuplanguageforsharingdocuments,ithasundergonemajorupdates,includingHTML2.0,whichintroducedforms;HTML3.x,whichaddedvisualenhancementsandlayout

It is a semantic tag used in HTML5 to define the bottom of the page or content block, usually including copyright information, contact information or navigation links; it can be placed at the bottom of the page or nested in, etc. tags as the end of the block; when using it, you should pay attention to avoid repeated abuse and irrelevant content.

To embed videos in HTML, use tags and specify the video source and attributes. 1. Use src attributes or elements to define the video path and format; 2. Add basic attributes such as controls, width, height; 3. To be compatible with different browsers, you can list MP4, WebM, Ogg and other formats; 4. Use controls, autoplay, muted, loop, preload and other attributes to control the playback behavior; 5. Use CSS to realize responsive layout to ensure that it is adapted to different screens. Correct combination of structure and attributes can ensure good display and functional support of the video.
