swape.net alireza balouch

6Feb/070

Semi-transparent png fix in IE6 with CSS

This example shows how you can show semi-transparent png images in IE and don't mess up the code in other browsers. It uses only CSS and no JavaScript.I use the attribute style to make a style for other browsers then IE. And I'm using the filter style that works only for IE in the normal section.But first you have to make a semi transparent png image.
Then make an div layer and set a class name "mydiv"

And here is the CSS code:

  1. .mydiv{
  2. background-repeat: repeat;
  3. position: relative;
  4. display: block;
  5. width:250px;
  6. height:200px;
  7. text-align: center;
  8. /* Mozilla Firefox and other non IE based browsers ignores the filter style*/
  9. filter:progid:DXImageTransform.Microsoft.AlphaImageLoader( enabled=true, sizingMethod=scale src="back_g.png");
  10. }   
  11.  
  12. /* IE ignores this part IE can not read styles with [attribute]*/
  13. .mydiv[class]{
  14. background-image: url(back_g.png);
  15. }
  16. body{
  17. background-image: url(BG.png);
  18. background-repeat: repeat;
  19. }

Since IE can not show semi-transparent png images, we have to use the filter style that only works in ie. But if we use this code we have to make sure that other browsers can show the png file as well. So we use the styles with attributes. And since IE can not read this part, we can put everything that IE dose not need to read there.

Tagged as: , , Leave a comment
blog comments powered by Disqus