ie png图片显示不正常 good

Directly inserting images in PNG format with transparency will leave you with a white spot when display in Internet Explorer. It makes your image looks ugly and this is really the last thing any web designer or webmaster would want on their website. Here’s a solution on how to solve this white spot and let the PNG transparency recovers.

Let’s take a look at the difference of PNG images (with transparency) on both major browsers: Mozilla Firefox and Internet Explorer 6

Mozilla Firefox

PNG with transparency blends in nicely with no problem

png in firefox How to: Achieve PNG Transparency in Internet Explorer 6.0

Internet Explorer 6.0

Internet Explorer does not turn your transparency transparent, thus leaving you with a big ugly white spot.

png in ie How to: Achieve PNG Transparency in Internet Explorer 6.0

Solution

Create a container to store your image. In this case I use a <div>. Create your <div> inside your <body>, just like this.

  1. <body>
  2. <divclass="flower"></div>
  3. </body>
<body>
<div class="flower"></div>
</body>

Next, create a <style> if you dont have one. Make sure they are between your <head></head>. Put the following css inside.

  1. <style>
  2. body{background-color:#000}
  3. div.flower{background:url(flower-transparent.png)no-repeat;height:100px;width:100px}
  4. </style>
<style>
body {background-color:#000}
div.flower {background:url(flower-transparent.png) no-repeat; height:100px; width:100px}
</style>

The CSS codes above displays your PNG image in a <div>. Works fine for Mozilla Firefox, but not for Internet Explorer. To get it working cross browser, create another set of css just for Internet Explorer right below your <style></style>. Insert the following codes.

  1. <!--[ifgteIE5]>
  2. <styletype="text/css">
  3. div.flower{
  4. background:none;
  5. filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='flower.png',sizingMethod='crop');
  6. }
  7. </style>
  8. <![endif]-->
<!--[if gte IE 5]>
<style type="text/css">
  div.flower {
  background:none;
  filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='flower.png' ,sizingMethod='crop');
  }
</style>
<![endif]-->

Your IE should now give you a perfect blend like the picture below.

png in ie2 How to: Achieve PNG Transparency in Internet Explorer 6.0

Download working example.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值