Home arrow Style Sheets arrow Page 3 - Styling a Blog`s Links Bar with CSS Sprites
STYLE SHEETS

Styling a Blog`s Links Bar with CSS Sprites


In this fifth article of a seven-part series, I demonstrate how to use a set of CSS sprites to define the visual style corresponding to the “normal” state of a navigation bar of a fictional blog site. The most complex facet of this process was to create the background image containing the corresponding sprites; the rest of the procedure merely involves manipulating the image’s X and Y coordinates via CSS.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
March 05, 2010
TABLE OF CONTENTS:
  1. · Styling a Blog`s Links Bar with CSS Sprites
  2. · Review: the source code so far
  3. · Using CSS sprites for styling the normal state of the navigation bar
  4. · Binding the CSS styles to the blog's structural markup

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Styling a Blog`s Links Bar with CSS Sprites - Using CSS sprites for styling the normal state of the navigation bar
(Page 3 of 4 )

Since the previous div, identified as "navbar," has already been styled with an artistic texture, the look of the navigation bar that I plan to construct here logically must be consistent with this. Therefore, the background image that I'll be using for defining the different states of the bar will be the following one (notice again that the image has been modified to fit in the screen size):

Even though the building elements of the links bar have a neat, sketchy appearance, the principle that will make them work is exactly the same as the one that you learned in earlier examples. Since each state of the bar's sections has been defined within the same background image, creating their "normal" state is as simple as coding the following CSS styles:  

/* About Me button */

ul#navbar li#about {

      width: 162px;

    height: 313px;

    background: transparent url("bg_blog_buttons.png") 0 0 no-repeat;

    position: absolute;

    top: 10px;

    left: 50px;

    text-indent: -9999px; 

}

/* Articles button */

ul#navbar li#articles {

    width: 162px;

    height: 343px;

    background: transparent url("bg_blog_buttons.png") 0 -314px no-repeat;

    position: absolute;

    top: 10px;

    left: 220px;

    text-indent: -9999px;

}

/* Blog button */

ul#navbar li#blog {

    width: 162px;

    height: 300px;

    background: transparent url("bg_blog_buttons.png") 0 -657px no-repeat;

    position: absolute;

    top: 10px;

    left: 390px;

    text-indent: -9999px;

}

/* Search button */

ul#navbar li#search {

    width: 162px;

    height: 355px;

    background: transparent url("bg_blog_buttons.png") 0 -956px no-repeat;

    position: absolute;

    top: 10px;

    left: 560px;

    text-indent: -9999px;

}

/* Contact button */

ul#navbar li#contact {

    width: 162px;

    height: 298px;

    background: transparent url("bg_blog_buttons.png") 0 -1311px no-repeat;

    position: absolute;

    top: 10px;

    left: 730px;

    text-indent: -9999px;

}

As seen above, defining the initial state of this sample links bar is reduced to assigning the appropriate X and Y coordinates to the earlier background image. In addition, you may have noticed that each element of the bar has been positioned absolutely with reference to the parent container. Considering that this process is entirely optional, you may want to use another approach and obtain practically the same results.

Finally, I must point out that the icon set used in this particular example is a creation of Jan Cavan (http://www.tutorial9.net/author/jancavan/) and can be freely downloaded from Tutorial9's website here (http://www.tutorial9.net/resources/sketchy-web-icons-30-hand-drawn-icon-pack/), which has plenty of other cool resources for web designers as well. Also, make sure to read the corresponding license, in case you're interested in using the icons in your own web projects.

Having clarified that point, it's time to attach the previous CSS styles to the markup of the sample blog site, so you can see how all of the pieces fit neatly together. This will be done in the next section, so click on the link below and read the next few lines.   


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 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials