上一篇:CSS3 实现未来的 Web
下一篇:Reset CSS研究(八卦篇)
ie6下png背景图使用iepngfix.htc也无效的分析
时间:2009-08-07 来源:未知 作者:未知 点击数:183
我们知道iepngfix.htc是解决ie6对png支持的最有效简单的方法,但在做网站的时候,却经常碰到即便使用了它也无法显示png透明背景图,如以下代码:
| <html> <head> <!--[if lte ie 6]> <script language="javascript" src="iepngfix_tilebg.js"></script> <![endif]--> <style type="text/css"> #box { width:500px; height:500px; border:1px solid #000; } #box div { background:URL(images/star.png) no-repeat center; width:300px; height:300px; _behavior:URL(iepngfix.htc); } </style> </head> <body> <div id="box"><div></div></div> </body> </html> |
虽代码无错,但结果IE6对PNG的解释无效。我们知道新版的iepngfix带了一个iepngfix_tilebg.js,这样可以给PNG透明背景图设置对齐位置,而之前老版本只有一个iepngfix.htc,png背景图不能设置对齐位置,,,怎么说呢,举个例子:
| #box div { background:URL(images/star.png) no-repeat 100px 200px; width:300px; height:300px; _behavior:URL(iepngfix.htc) |
光只有iepngfix.htc, star.png的左+100px 上+200px对齐方式无效,默认为 0 0。
如果在开头代码中加入:
| <!--[if lte ie 6]> <script language="javascript" src="iepngfix_tilebg.js"></script> <![endif]--> |
star.png的左+100px 上+200px对齐方式有效,但问题就出在这里!我们将这段代码去掉虽然位置成0,但ie6能显示透明的png,加上反而就不行,但是有些透明png还是显示了出来,怎么会有些显示,有些不显示呢,我不知道,但通过我多次实验,发现用div设png背景图ie6才无效,如果换成p或者span等等,都没有问题! 说不清楚,还是举例吧,以上面第一个例子做修改如下:
| <html> <head> <!--[if lte ie 6]> <script language="javascript" src="iepngfix_tilebg.js"></script> <![endif]--> <style type="text/css"> #box { width:500px; height:500px; border:1px solid #000; } #box span { background:URL(images/star.png) no-repeat center; width:300px; height:300px; _behavior:URL(iepngfix.htc); display:block; } </style> </head> <body> <div id="box"><span></span></div> </body> </html> |
问题解决!
| 来顶一下 |
上一篇:CSS3 实现未来的 Web
下一篇:Reset CSS研究(八卦篇)
