Style Sheets
  Home arrow Style Sheets arrow Page 3 - Building a Dynamic Banner with CSS Sprites
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 
Sun Developer Network 
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

Building a Dynamic Banner with CSS Sprites
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2007-02-19

    Table of Contents:
  • Building a Dynamic Banner with CSS Sprites
  • Building a banner the classic way
  • Rebuilding the dynamic banner as a two-image CSS sprite
  • Listing the complete source code for the banner

  • 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


    Building a Dynamic Banner with CSS Sprites - Rebuilding the dynamic banner as a two-image CSS sprite


    (Page 3 of 4 )

    As I said in the previous section, creating a dynamic banner using a CSS sprite is indeed a simple process that can be performed with minor hassles. Basically, we will create a single background image that contains the respective stages of the banner in question.

    To clarify this process, below I included a reduced version of the background image that I'm going to use with the sample banner. It looks like this:

    Having at our disposal the above background image, creating the CSS styles that implement the sprite is as simple as this:

    <style type="text/css">
     
    body{
         padding: 0;
         margin: 0;
         background: #fff;
     
    }

      h1{
         font: bold 24px Arial, Helvetica, sans-serif;
         color: #000;
         text-align: center;
     
    }

      #bannercontainer{
          width: 400px;
          height: 100px;
          padding: 0;
          margin-left: auto;
          margin-right: auto;
          background: #eee;
          border: 1px solid #000;
     
    }

      #bannercontainer a{
          display: block;
          width: 400px;
          height: 100px;
          padding: 0;
          background:#eee url(banners.jpg) 0 0 no-repeat;
     
    }

      #bannercontainer a:link,a:visited{
          background:#eee url(banners.jpg) 0 0 no-repeat;
     
    }

      #bannercontainer a:hover{
          background:#eee url(banners.jpg) -400px 0 no-repeat;
     
    }
    </style>

    That's was really easy, wasn't it? As you can see, the above CSS declarations are really simple to grasp. All they do is change the position of the previous background image at each stage of the link where the banner will be included. Similar to the rollover example that you learned in the first part of the series, this case implements the same logic.

    Now do you realize the neat functionality provided by CSS sprites in different situations? I bet you do!

    Okay, at this point I'm pretty sure that you grasped the logic that stands behind using a CSS sprite for creating the prior sample banner. However, the CSS code that corresponds to the previous example looks rather disconnected, since it hasn't been attached to the respective structural markup.

    Therefore, in the course of the section to come, I'm going to show you the complete source code that implements this simple CSS sprite-based banner. You can quickly copy it and paste it into your favorite text editor.

    As usual, to see how the full code of this dynamic banner looks, click on the link below and keep reading.

    More Style Sheets Articles
    More By Alejandro Gervasio


       · Over the course of this second part of the series, a sample banner is created by...
     

    STYLE SHEETS ARTICLES

    - Improving the Visual Presentation of a CSS D...
    - Fixing Browser Incompatibilities in a CSS Dr...
    - Building Clean Drop-Down Menus with CSS
    - Creating Hybrid Web Page Layouts with Negati...
    - Creating Three-Column Web Page Layous with N...
    - Swapping Column Positions in Web Page Layout...
    - Creating Web Page Layouts with Negative Marg...
    - Creating Gradients for Individual Containers...
    - Creating Gradients for Web Page Headers with...
    - SEO Scrolling Frames Problem Solved
    - Building Cross-Browser Background Effects wi...
    - CSS: Pseudo
    - Using PNG Images to Build Background Effects
    - CSS: Continuing the Clarification of CSS Cla...
    - CSS: Top Secret Classification






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT