Home arrow Style Sheets arrow Page 3 - Building Cross-Browser Background Effects with PNG Images
STYLE SHEETS

Building Cross-Browser Background Effects with PNG Images


One of the most useful characteristics of PNG images (also called “pings”) is their great support for alpha-based transparency, a feature that makes them ideal for building professional-looking web page gradients. Nonetheless, as you possibly know, Internet Explorer 6 doesn’t render these graphics correctly when they contain transparent sections. Keep reading to find out how we can fix this problem.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 4
May 20, 2008
TABLE OF CONTENTS:
  1. · Building Cross-Browser Background Effects with PNG Images
  2. · Review: Working with alpha-transparent PNG graphics
  3. · Building cross-browser web page gradients with Microsoft’s proprietary AlphaImageLoader method
  4. · Building a web page gradient that will work the majority of modern browsers

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building Cross-Browser Background Effects with PNG Images - Building cross-browser web page gradients with Microsoft’s proprietary AlphaImageLoader method
(Page 3 of 4 )

In the course of the previous section I provided you with a demonstrative hands-on example of how to create a web page gradient by using only a small PNG image, which was repeated horizontally across the pertinent web document via a simple CSS style. Nonetheless, while this example will work neatly on most non IE browsers, the truth is Internet Explorer has serious problems displaying transparent PNG graphics.

Considering the aforementioned issue, it’s necessary to implement some kind of CSS workaround that allows you to build these web page gradients in a true cross-browser fashion. Fortunately, the solution for this IE-related problem is just around the corner, thanks to the technique introduced initially by Mathew O’ Neil in the following article: http://www.alistapart.com/articles/supereasyblendys.  

However, I’m going to save your valuable time and explain how this approach works in simple terms. Among the huge arsenal of visual filters that come bundled with IE 6, there’s one that's very useful in this case, called “AlphaImageLoader.” It comes in handy for attaching a given PNG image to a specific web page element.

Of course, the major advantage of using this filter is that the image in question will be correctly displayed by IE 6 and below, even if it contains transparent sections. Sounds pretty promising, right?

Therefore, based on the functionality provided by Microsoft’s proprietary filter, it’s possible to implement a simple CSS workaround that permits you to apply the  filter to the background of a selected web page only when IE is utilized, while all the other browsers should use the approach that you learned in the previous tutorial.

Actually, this concept may sound rather confusing at first, but if you have a look at the following CSS styles, you shouldn’t have major problems understanding how this workaround works:


.gradient{

background: #fff url(bg.png) left top repeat-x;

}

/* use the * html CSS hack to render an alpha-based transparent background */

* html .gradient{

background: #fff;

filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='bg.png',
sizingMethod='scale');

}


First, I created a simple “gradient” class that will attach the pertinent PNG background image to a selected web page element. Second, I used the aforementioned “AlphaImageLoader” -- Microsoft’s proprietary filter -- to include the same image only when using IE 6 and below. In this last case, the definition of this class will simply be overridden by all IE browsers, because of the utilization of the * html selector, which is only recognized by them. Easy to grasp, right?

So, at this point you’ve learned a simple, effective CSS workaround that is very useful for displaying transparent PNG images on most modern browsers. It creates a true cross-browser approach that can also be utilized for building the fancy web page gradient that you saw previously.

However, if you’re anything like me, surely you’ll want to see how the prior CSS workaround can be linked with the corresponding structural markup of a sample web page to create PNG-based backgrounds. Thus, in the upcoming section, I’m going to set up a complete hands-on example that will show you how to build a web page gradient that uses the alpha-based transparency.

To see the details of this process, go ahead and read the next few lines. They’re only click away.


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials