Style Sheets
  Home arrow Style Sheets arrow Page 4 - Using PNG Images to Build Background Effec...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Using PNG Images to Build Background Effects
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 6
    2008-05-13

    Table of Contents:
  • Using PNG Images to Build Background Effects
  • Building background gradients using a simple JPG image
  • Building a basic background gradient using a GIF image
  • Building a fancy web page background with a PNG graphic: introduction

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using PNG Images to Build Background Effects - Building a fancy web page background with a PNG graphic: introduction


    (Page 4 of 4 )

    In accordance with the concepts I deployed in the prior section, it’s perfectly feasible to build fancy web page backgrounds by utilizing a single, partially-transparent PNG image along with a solid color. However, to achieve the correct color fading effect, a browser must natively support alpha-based transparency with PNG graphics, which, as I stated earlier, is not a strong point of Internet Explorer 6 and below.

    So I’m going to show you how to build the same gray-colored web page background that you saw in the previous section, but in this particular case, by using a partially-transparent PNG graphic. Of course, you should be aware that this approach will work only in most non IE-based browsers.

    Having said that, here’s the corresponding definition of the sample (X)HTML file that displays the aforementioned web page background:


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <title>Sample web page with PNG-based background (Does not work in IE)</title>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <style type="text/css">

    body{

    padding: 0;

    margin: 0;

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

    }

    h1{

    padding: 5px;

    margin: 0;

    font: bold 12px Arial, Helvetica, sans-serif;

    color: #000;

    }

    h2{

    padding: 7px 5px 8px 5px;

    margin: 0;

    background: #fc0;

    font: bold 12px Arial, Helvetica, sans-serif;

    color: #000;

    }

    p{

    font: normal 12px Arial, Helvetica, sans-serif;

    color: #000;

    }

    #header{

    width: 780px;

    padding: 10px;

    margin-left: auto;

    margin-right: auto;

    background: #fc0;

    }

    #navbar{

    width: 780px;

    padding: 10px;

    margin-left: auto;

    margin-right: auto;

    background: #ffc;

    }

    #navbar ul{

    list-style: none;

    }

    #navbar li{

    display: inline;

    padding-right: 4%;

    }

    #navbar a:link,#navbar a:visited{

    font: normal 12px Arial, Helvetica, sans-serif;

    color: #039;

    text-decoration: none;

    }

    #navbar a:hover{

    text-decoration: underline;

    }

    #mainwrapper{

    clear: both;

    width: 800px;

    height: 100%;

    margin-left: auto;

    margin-right: auto;

    overflow: hidden;

    background: #fff;

    }

    #mainwrapper .leftcol{

    position: relative;

    float: left;

    }

    #mainwrapper .rightcol{

    position: relative;

    float: right;

    }

    #leftbar{

    width: 180px;

    padding: 10px;

    }

    #centerbar{

    float: left;

    width: 380px;

    padding: 10px;

    background: #fff;

    }

    #rightbar{

    width: 180px;

    padding: 10px;

    }

    #footer{

    clear: both;

    width: 780px;

    padding: 10px;

    margin-left: auto;

    margin-right: auto;

    background: #fc0;

    }

    .contbox{

    padding: 10px;

    margin-bottom: 10px;

    background: #eee;

    border: 1px solid #ccc;

    }

    </style>

    </head>

    <body>

    <div id="header">

    <h1>This is the header section of the web page</h1>

    <p>Contents for header section go here. Contents for header section go here. Contents for header section go here. Contents for header section go here.</p>

    </div>

    <div id="navbar">

    <h1>This is the navigation bar of the web page</h1>

    <ul>

    <li><a href="#">Link 1</a></li>

    <li><a href="#">Link 2</a></li>

    <li><a href="#">Link 3</a></li>

    <li><a href="#">Link 4</a></li>

    <li><a href="#">Link 5</a></li>

    <li><a href="#">Link 6</a></li>

    </ul>

    </div>

    <div id="mainwrapper">

    <div id="leftbar" class="leftcol">

    <h2>Section title</h2>

    <div class="contbox">

    <p>Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here.</p>

    </div>

    <h2>Section title</h2>

    <div class="contbox">

    <p>Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here.</p>

    </div>

    </div>

    <div id="centerbar" class="leftcol">

    <h2>Section title</h2>

    <div class="contbox">

    <p>Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here.</p>

    <p>Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here.</p>

    <p>Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center column go here.</p>

    </div>

    </div>

    <div id="rightbar" class="rightcol">

    <h2>Section title</h2>

    <div class="contbox">

    <p>Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here.</p>

    </div>

    <h2>Section title</h2>

    <div class="contbox">

    <p>Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here. Contents for left column go here.</p>

    </div>

    </div>

    </div>

    <div id="footer">

    <h1>This is the footer section of the web page</h1>

    <p>Contents for footer section go here. Contents for footer section go here. Contents for footer section go here. Contents for footer section go here. Contents for footer section go here.</p>

    </div>

    </body>

    </html>


    As you can see in the above example, the pertinent web page background is built by utilizing a tiny PNG image that fades progressively to transparency. In this way, it blends with the solid white color specified for the “body” selector.

    Finally, to complement the previous hands-on example, below I included an image that shows the visual appearance of this PNG-based web page background. Here it is:



    Indeed, this is a technique that permits you to create fancy web page gradients very easily, even though it’s not going to work with IE-based browsers. It was originally introduced by Mathew O’ Neil in the following article: http://www.alistapart.com/articles/supereasyblendys. If you’re interested in learning a bit more about this approach, it’s really worth reading.

    Final thoughts

    In this first chapter of the series, you learned a few straightforward approaches for building fancy web page gradients using partially-transparent PNG images. However, as I explained earlier, IE 6 and below do not display graphics that use alpha-based transparency.

    Thus, considering this, in the next part, I’m going to implement a simple CSS workaround in order to develop a cross-browser solution that allows you to build consistent web page gradients using transparent PNG graphics.

    Don’t miss the next article!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · PNG images can be used to build light-weight background effects, even when Internet...
     

    STYLE SHEETS ARTICLES

    - Image Replacement CSS Techniques
    - Using BlueTrip`s Success, Notice and Error C...
    - More Uses for the Thin and Caps CSS Classes ...
    - Styling Definition Lists with the BlueTrip C...
    - Styling Unordered and Ordered HTML Lists wit...
    - Using the BlueTrip CSS Framework`s Thin and ...
    - Adding Borders to Web Page Columns with Blue...
    - Introducing the BlueTrip CSS Framework
    - Using a Background Grid to Assist Web Page L...
    - Extending the Rule Of Thirds for Web Page La...
    - A Two-Column Web Page Layout Based on the Ru...
    - Using the Rule Of Thirds for Web Page Layout
    - Swapping Columns Using the Divine Ratio for ...
    - Using the Golden Ratio in Liquid Web Page De...
    - Fundamental Design Principles for Web Page L...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek