We launched a new IT training category! Check out the 140+ courses now.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Solution: Enhancing navigation with CSS

From: CSS: Styling Navigation

Video: Solution: Enhancing navigation with CSS

So how did your button turn out? Are you happy with it? It's amazing how much variety you can get combining just a few properties. Let's take a look at the finish files and compare them with yours. You should have paid attention to not only which properties I use with things like the button, but also how I wrote the selectors and structured the styles, especially for the sprites. I'm really curious to see how closely your code matches mine, and again, if it doesn't, it's not wrong, especially if it was working. You just want to take a look at your code versus my code and see which one might be more efficient, see which approach you'll like a little bit better.

Solution: Enhancing navigation with CSS

So how did your button turn out? Are you happy with it? It's amazing how much variety you can get combining just a few properties. Let's take a look at the finish files and compare them with yours. You should have paid attention to not only which properties I use with things like the button, but also how I wrote the selectors and structured the styles, especially for the sprites. I'm really curious to see how closely your code matches mine, and again, if it doesn't, it's not wrong, especially if it was working. You just want to take a look at your code versus my code and see which one might be more efficient, see which approach you'll like a little bit better.

And you know what? If it ends up being your approach, that's fine. There's nothing saying that you didn't write more efficient selectors than me. Just to give you an idea of kind of what I came up with, I've showed you this earlier, but this is the button that I created. So a very simple button, it's got a nice looking gradient in it, I'm using a small little bevel up top, using the same blue color which really kind of goes with the site. And then for my sprites, again ,all four icons are showing up, and then I have the rollovers working as well, cool. So I'm going to switch over my code, and the first thing I'm going to do is focus on the button. I'm just going to scroll all the way down until I find that button.

And it's pretty easy to find, you can't miss it, there it goes, it's on line 791. When you hit it, you know it. All right, so here is my button, and I'm just going to go through line by line and talk about the different things that I did. So I set the color to white so that the text will be white. I gave it a little bit of padding, so the text will be held away from the edge of the button. I changed the font size to 1 em, that's pretty much the default, but buttons are a lot different, especially in all the different user agents. So I want make sure if they're all basically the same size. I applied a cursor pointer, that's really not necessary for this because input types submits are almost always going to show the pointer, but hey, I just want to be thorough.

I then did a small 1-pixel border, sort of that darker blue color. It's not real dark, but it's going to give it a nice little offset. I did a box shadow, and both of these apply the box shadow to it, and it's very similar to what we did before. I did an inset, so I can have little of that sort of highlight bevel, but this one is even smaller. I did 1 pixel for vertical, and I did only 1 pixel for the radius, so very, very sharp. And then I did almost white, you can see very light, light blue. I applied a border radius to it of 5 pixels. It's going to round the corners a little bit.

And then I did my backgrounds, and you can guess where I generated this particular gradient from. So I have a default RGB color of that, sort of blue that we're using all the way throughout the site. And then after that I went ahead and did a gradient. I started that out with the blue color that's prevalent throughout site, and then I went to a lighter blue. And then I just went ahead and did the syntax for all of the remaining browsers as well. So that's the button, pretty simple. It creates a very nice pleasing effect, and I could use these styles over and over again. Now as far as the rollover goes, if I scroll down a little bit, you can see that for hovering, again, the only thing I really did there, I changed the background so that their gradient goes in a separate direction, and I made the color just a little dimmer.

So it's almost like a little neutral gray with little blue tint to it. So it's not bright and shiny white. Okay, so there was my button. So I'm going to scroll up and show you guys how I handled these sprites, and I'm going to start right here at the one of the selectors that wasn't existing selector. I know I told you guys we're going to have to write new selectors. I went ahead and threw you a curveball here, so the connect li a, that's going to target-- again--any link inside of a list item that's also inside that connect region. So what it did was the text-indent, -999 ems, that was already there, that was taken the text and sort of getting rid of it. It's just pushing it off the page.

The width and the height are already there, 45 pixels by 45 pixels is displaying as block-level element, that stuff was already there, but what wasn't there was the background, that brings the social sprites in. Again, you want to make as few requests for this image as you can. So you only request it one time, and you request it on like a global version of that link. And then all you have to do, after that is simply position it. And you'll notice that I've got several selectors that do that for me. So I've the static version of the button, and then I have a hover. And I did something a bit little different.

Then you may or may not have done this, if you did, it's fine, if you didn't know about it, didn't do it, that's cool too. But notice that for certain ones like the first and the last one, I'm able to use keywords instead of values. By saying left top, I'm saying position the top left corner of the graphic to the top left corner of this link. And since they're both 45 pixels by 45 pixels, it's going to line up perfectly. Since the hover is just the right below it, I'm able to say left bottom then it doesn't work for the other ones. So for the other ones I had to move over. So remember, there's my horizontal value, and there's my vertical value.

Because I want it to move to the right, I had to use negative values for horizontal, so I went -45 and 0. And then for the bottom ones, I'm using -45 there as well. So again -45, -45, and then I just step over, so -90, 0, that's going to keep it, again, against the top portion. And then -90 over to the right and then -90 over to the right and 45 pixels down for the hover. And then finally for link, I was able to use right top and right bottom, it sort of mirrors left top and left bottom.

See, it's a lot easier when you have sprites that are really tightly packed together and they're spaced evenly. In our exercise files earlier, we had to do a lot of tweaking those to get them to position exactly where we want. When you set them in position and right up against each other, when you're absolutely positively sure that the area is going to shrink wrap to this icon, that sure is a lot easier. All right, so once again just to sort of preview how that's working, there is our sprites, and there is our button. We'll, there you go, that was your last lab. Yeah, I hope you had a great time exploring how styling navigation can enhance your sites.

Be sure to watch the additional resources movie. I'm going to show you a few tools and resources that can really help when it comes time to plan and style your site's navigation.

Show transcript

This video is part of

Image for CSS: Styling Navigation
CSS: Styling Navigation

53 video lessons · 17398 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 3m 8s
    1. Welcome
      42s
    2. What you should know before watching this course
      1m 12s
    3. Using the exercise files
      1m 14s
  2. 35m 25s
    1. Organizing menus with lists
      4m 26s
    2. Ensuring accessibility
      9m 3s
    3. Using the nav element
      7m 30s
    4. Creating block-level links
      3m 8s
    5. Lab: Structuring navigation
      4m 11s
    6. Solution: Structuring navigation
      7m 7s
  3. 48m 42s
    1. Exploring link style considerations
      9m 2s
    2. Using global link styles
      9m 56s
    3. Styling link states
      10m 57s
    4. Indicating external links
      10m 4s
    5. Styling image links
      8m 43s
  4. 52m 5s
    1. Stripping default list styling
      4m 34s
    2. Defining link dimensions
      6m 0s
    3. Setting link styling
      3m 36s
    4. Aligning links vertically
      4m 11s
    5. Controlling link spacing
      2m 30s
    6. Styling menus with borders
      2m 32s
    7. Creating rollovers
      4m 45s
    8. Restricting link styling
      3m 31s
    9. Lab: Creating a vertical menu
      11m 44s
    10. Solution: Creating a vertical menu
      8m 42s
  5. 54m 58s
    1. Stripping list styling
      3m 35s
    2. Displaying links horizontally
      6m 14s
    3. Clearing floats
      6m 12s
    4. Controlling link sizing and spacing
      3m 11s
    5. Styling links
      7m 16s
    6. Creating rollovers
      5m 52s
    7. Indicating current pages
      4m 43s
    8. Controlling cursor states
      2m 46s
    9. Lab: Creating horizontal menus
      6m 45s
    10. Solution: Creating horizontal menus
      8m 24s
  6. 55m 35s
    1. Overview of dropdown menus
      1m 17s
    2. Structuring submenus
      5m 56s
    3. Styling submenus
      6m 4s
    4. Creating submenu rollovers
      3m 28s
    5. Positioning submenus
      5m 43s
    6. Controlling submenu display
      5m 5s
    7. Creating persistent hover states
      5m 53s
    8. Animating menus with CSS transitions
      6m 29s
    9. Lab: Dropdown menus
      6m 51s
    10. Solution: Dropdown menus
      8m 49s
  7. 58m 7s
    1. Creating CSS-only buttons
      8m 39s
    2. Creating special effects for buttons
      4m 2s
    3. Enhancing buttons with gradients
      7m 40s
    4. Overview of CSS sprites
      3m 30s
    5. Using CSS sprites for icons
      14m 30s
    6. Styling block-level links
      8m 38s
    7. Lab: Enhancing navigation with CSS
      5m 26s
    8. Solution: Enhancing navigation with CSS
      5m 42s
  8. 6m 29s
    1. Additional resources
      6m 29s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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

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 CSS: Styling Navigation.

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 ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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.