Site Navigation with CSS in Dreamweaver
Illustration by John Hersey
Watching:

Implementing sprites


From:

Site Navigation with CSS in Dreamweaver

with Joseph Lowery

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now

Video: Implementing sprites

One technique for incorporating imagery with navigation is to use multiple graphic files--one for each link state: link visited, hover, and active. While effective, this method does require a number of file requests to the host server, which can quickly add up, increasing the bandwidth and response time. Another technique, referred to as sprites, uses a single image for all states and is accomplished with just a little CSS manipulation. Let's take a look at an example. Here I have the mission.htm file here, and as I roll over each of the main navigation items, you see that the background image, which is the star and the line, changes and the text also changes. But it's really the background image that we are looking at here. And this is a single image that is being repositioned using the CSS background position property.
Expand all | Collapse all
  1. 2m 20s
    1. Welcome
      1m 2s
    2. Using the exercise files
      1m 18s
  2. 9m 26s
    1. Using icons in navigation
      2m 14s
    2. Understanding 3D nav bars
      2m 25s
    3. Understanding explanatory navigation
      1m 51s
    4. Creating animated navigation
      2m 56s
  3. 1h 14m
    1. Inserting Spry horizontal menus
      7m 4s
    2. Styling Spry menus
      6m 29s
    3. Adding Spry vertical menus
      5m 7s
    4. Styling Spry vertical menus
      10m 53s
    5. Using Spry tabbed navigation
      9m 33s
    6. Styling Spry tabbed menus
      9m 55s
    7. Including Spry accordion panel menus
      5m 32s
    8. Styling Spry accordion menus
      11m 10s
    9. Advanced Spry menu techniques
      8m 32s
  4. 35m 45s
    1. Converting lists to menus
      7m 56s
    2. Working with background images
      5m 47s
    3. Implementing sprites
      5m 53s
    4. Setting up adjustable backgrounds
      9m 4s
    5. Designing accessible navigation
      7m 5s
  5. 30m 34s
    1. Looking at the project
      1m 4s
    2. Building up the basic HTML
      2m 9s
    3. Displaying top-level links horizontally
      8m 12s
    4. Customizing the link states
      4m 29s
    5. Adding drop-down menus (HTML)
      3m 48s
    6. Working with submenus (CSS)
      4m 8s
    7. Achieving interactive submenus
      2m 21s
    8. Marking the current page
      4m 23s
  6. 23m 13s
    1. Looking at the project
      57s
    2. Understanding vertical menus
      2m 15s
    3. Defining width for link elements
      4m 43s
    4. Using background graphics with navigation
      5m 45s
    5. Creating pop-out vertical navigation
      6m 29s
    6. Setting link states
      3m 4s
  7. 10m 13s
    1. Identifying anchor tags
      7m 4s
    2. Identifying external links
      3m 9s
  8. 18m 14s
    1. Creating jQuery animated image menus
      7m 45s
    2. Using the HTML5 nav tag
      3m 24s
    3. Exploring CSS3 enhancements
      7m 5s
  9. 28s
    1. Next steps
      28s

please wait ...
Watch the Online Video Course Site Navigation with CSS in Dreamweaver
3h 24m Intermediate Mar 22, 2011

Viewers: in countries Watching now:

Join Joseph Lowery in Site Navigation with CSS in Dreamweaver as he explores current design trends in site navigation and shows designers and developers how to create robust CSS-based navigation. The course shows how to convert HTML lists to graphical controls that integrate seamlessly with an existing site design, and how to build menus with a wide range of navigation options, all in standards-compliant CSS. Exercise files accompany the course.

Topics include:
  • Using icons
  • Navigating with Spry widgets
  • Styling Spry menus
  • Working with background images
  • Implementing sprites
  • Designing navigation with accessibility in mind
  • Adding drop-down menus
  • Developing graphical navigation with jQuery
  • Creating pop-out vertical navigation
  • Exploring CSS3 and HTML5 enhancements
Subject:
Web
Software:
Dreamweaver
Author:
Joseph Lowery

Implementing sprites

One technique for incorporating imagery with navigation is to use multiple graphic files--one for each link state: link visited, hover, and active. While effective, this method does require a number of file requests to the host server, which can quickly add up, increasing the bandwidth and response time. Another technique, referred to as sprites, uses a single image for all states and is accomplished with just a little CSS manipulation. Let's take a look at an example. Here I have the mission.htm file here, and as I roll over each of the main navigation items, you see that the background image, which is the star and the line, changes and the text also changes. But it's really the background image that we are looking at here. And this is a single image that is being repositioned using the CSS background position property.

Let's take a look at that actual image, which I have here. Now, you will notice that this has actually three different states, and we are only using the first two so far, but as I will show you in just a moment, you can easily add the third state. You can easily develop sprite images like this one in your favorite graphics editor, such as Photoshop or Fireworks. Let's go back and take a closer look at the CSS for the link and hover. Go back to my mission.htm page and open up our CSS Styles panel, and in the SprymenuBarVertical.css file, let's go down to the anchor tag called ul.menuBarVerticalanchor. And here you see the background image, and if I open it up into the Edit Rule, you can see that it's set up using the background position elements here, setting it to left and top. And that's going to show the very first image, which is that darker green gray star that we see here. Okay.

Let's take a look now at the hover state, and here you see that just a couple of rules down at ul.menuBarVertical a:hover, and it also covers the focus state as well. So, I will select that, and notice that there's not a second call for the background image here as you might suspect, but instead there is a background position. Let me see if I can open that up just a little bit, so you can see the full thing. There is the background-position property just repositioning the existing graphic. This value here is 272 pixels for the left, and how do you get that value? Well, let's go over and take a look at the actual graphic.

You can actually size this up either in your graphics program, or if you don't have that handy, you can do it within Dreamweaver. So, I have my image selected and my rulers are on. I am going to pull out a guide and have that lock to the start of the image. And now as I pull out a second rule, I am going to hold down the Command key on the Mac and you would hold down the Ctrl key on the PC. And as I do it, you can see the measurement there now is at 210-225 and it goes up to the end of the first graphic, which is 272. And that's the actual measurement that I want to use, but you set it in negative, because you are going to be pushing the graphic off to left, so it will actually start right here.

So, that's why the orange shows up on hover. So, we can use the same technique to set up a third state. I am going to go ahead and bring my guide over and hold down my Command key so I see at the end here, it's 540 pixels. So we see that it has a measurement of 544 pixels, so we'll use -544 pixels to position it for the third state. Let's switch back to our mission.htm file, and what we want to do is set it up so that since we are on the mission page that the Mission navigation item is shown as selected using that third section of the sprite.

So, we are going to create a new rule, and this will be a Compound rule, and again, we are going to target the ul.MenuBarVertical class, then look for the list item and the anchor tag. Now, I am going to add an additional class to this to indicate that it is the currently selected page. I will just call that current and click OK. And we go to the Background category and in the Background-position, we choose -544.

Now I am going to go ahead and put in a 0 here to avoid problems with some browsers. So, the other thing I want to do in this new rule is change the color for the type to match that background image, which is a medium gray of 666. So, with that done, let's go ahead and click OK, and the next step is to add that class that we talked about to the Mission tag here. So, I'll go into the Split view, close off the panel.

Let's go ahead and click on that to bring that in to view, and we want to add this as a class here. Now, you can use multiple classes in Dreamweaver, so I am just going to type a space and add a new class of current. And you can see as I start to type it, Dreamweaver uses code hints to pinpoint the exact one I am looking for. So I will go ahead and just hit Return. And let's flip back to Design view now, and because we are in Live view, you can see it's already been updated. I now have my third state showing with both text and graphics. Thanks to the CSS Background-position property, integrating different sprite positions into your navigation states is a very clean, and dare I say refreshing, approach.

There are currently no FAQs about Site Navigation with CSS in Dreamweaver.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Site Navigation with CSS in Dreamweaver.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.