Home arrow Style Sheets arrow Page 2 - Building CSS Sprite-Based Navigation Bars
STYLE SHEETS

Building CSS Sprite-Based Navigation Bars


In this first part of a series, we'll start building a stylish navigation bar which uses a combination of image replacement and CSS sprites to define the visual presentation of its sections. The resulting bar will have a clean, professional look that would be at home on any corporate web site.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
February 26, 2010
TABLE OF CONTENTS:
  1. · Building CSS Sprite-Based Navigation Bars
  2. · Defining the navigation bar's structural markup
  3. · Defining the CSS styles for the normal state of the navigation bar
  4. · Including the previous CSS styles in the sample web page

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building CSS Sprite-Based Navigation Bars - Defining the navigation bar's structural markup
(Page 2 of 4 )

To start demonstrating how a balanced combination of image replacement and CSS sprites can be of great help in building an elegant navigation bar, we must start by defining the bar's structural markup. Since my goal here is to create an attractive navigational mechanism that also offers a decent level of accessibility, its bare bones structure will be comprised simply of an unordered list and a few additional items.

Having explained that, here's the web page that will contain the corresponding HTML list:

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Stylish navigation bar using CSS sprites</title>

</head>

<body>

<div id="wrapper">

<div id="header">

<h1>Stylish navigation bar using CSS sprites</h1>

<ul id="navbar">

<li id="about"><a href="#" class="active">About Us</a></li>

<li id="services"><a href="#">Services</a></li>

<li id="products"><a href="#">Products</a></li>

<li id="articles"><a href="#">Articles</a></li>

<li id="blog"><a href="#">Blog</a></li>

<li id="contact"><a href="#">Contact</a></li>

</ul>

</div>

<div id="content">

<h2>Main content section</h2>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

</div>

<div id="footer">

<h2>Footer section</h2>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

</div>

</div>

</body>

</html>

The previous (X)HTML document defines the typical header, content and footer sections that are so commonly seen on any website. However, the most interesting of these three areas is certainly the header. It houses a standard unordered list, which will be the building block of the navigation bar discussed in the introduction.

For demonstrative purposes the list in question only includes a few hyperlinks, such as the ones that point to the "Services," "Products" and "Contact" sections of a fictional website. Naturally it's possible to add extra items in accordance with more specific requirements. In addition, you may have noticed that the link within the "About Us" section has been assigned a class named "active." The reason to assign this class is to indicate visually to users which section they're currently viewing, so for now don't be too concerned about the rationale behind coding this class.

So far, so good. At this stage things look pretty good, since the structure of the navigational bar that I plan to build is based on clean, standard markup. So, what's the next step? Well, with the skeleton of the bar already set up, now we need to create the CSS styles that make it look really stylish.

Here's where CSS sprites will come into play, but the full details of the styling process will be discussed in the following segment. Therefore, click on the link below and keep reading.


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