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

Styling links

From: CSS: Styling Navigation

Video: Styling links

Just as with our vertical menu, the choices that you make for the visual style of the menu are what really sets it apart and makes it unique. You're free to use colors, gradients, images, icons, font formatting, and all sorts of custom styling to get your menus to look exactly the way that you want them to. We're going to get our menu closer to the desired styling by controlling the visual formatting for multiple elements. So in this exercise, I want you to pay close attention to how the styling of several elements is going to combine to create the final menu.

Styling links

Just as with our vertical menu, the choices that you make for the visual style of the menu are what really sets it apart and makes it unique. You're free to use colors, gradients, images, icons, font formatting, and all sorts of custom styling to get your menus to look exactly the way that you want them to. We're going to get our menu closer to the desired styling by controlling the visual formatting for multiple elements. So in this exercise, I want you to pay close attention to how the styling of several elements is going to combine to create the final menu.

Here I have the horizontal.htm open from the 04_05 directory. I'm going to scroll down until I get to my list styling here. So we're just picking up right where we left off before. Now the first thing I want to do, I'm going to sort of revisit that nav selector that we created earlier. If you remember from looking at the finished version of the horizontal menu at the beginning of this chapter, it has a two-toned bar, a sort of a lighter orange color, and a darker brown color underneath that.

So to start that, use the nav element. Remember, that's the very top parent element for our menu. So I'm just going to go to nav, and inside this selector, I'm going to set a background color, and I want the background to be #916A31, and that's a sort of darker orange color, if you will. I'm going to go ahead and save that. And if I preview this in a browser, the nav element is stretching the entire length of its parent element, which in this case is the body tag.

And I want to point out something about the height of this. You notice that we did not specify a height on the nav, so the nav's height currently is being controlled by its contents, which in this case is the line-height on each of the link items. The default styling here of the blue text and the underline, that's probably not going to cut it for this menu. So let's go back into our styles here for the list item a selector, the one targeting links inside the list items. I'm going to go inside that and change the color to white for the text.

For text decoration, I'm just going to go ahead and remove that underline by typing none. So I'm going to save that, go back into the browser and refresh that, and that looks a lot better. So now we have white text, no underline, and remember, anytime you're going to remove the underline-- which is very common in menus--most people will remove the underline in menus. You have to give some other visual indication that it's a link. Being part of a menu structure is a very strong visual indication in this part of the link, and of course we are also going to have some rollovers that's going to help with that as well.

You may have remembered from earlier that we have that sort of two-toned look to this horizontal menu bar. So we had the lighter orange that was the much wider part of the bar, and then that darker orange color you're seeing currently into the nav is being a very smaller portion of it. So how is that effect achieved? Well, we could have used a border, we could have given the nav element the brighter orange color and then used a border on the bottom of it. Of course, there is always more than one way to achieve an effect, and sometimes you have to choose a method based on what else you have going on within that particular element, in this case the menu.

So let me kind of show you how we're going to be building this. I'm going to take the ui, li group selector, and I'm going to create another selector just below that. I like keeping things kind of in the order that they appear. So I'm going to type in a ul, I'm just targeting the unordered list now. I'm isolating it as apart from the styling here. And I'm going to give it a background color, the same way I did the nav element. Now this is going to be that brighter orange color so that's #D5973C, and we've used that color so much in this course.

And I'm sure some of you guys already have that memorized. We're going to do something a little different here. I'm going to go ahead and define a height for this unordered list. So I'm going to use 2 ems. You may have noticed that that's exactly the same as the line-height. So you are probably saying to yourself, well, isn't that kind of redundant? For right now it is, but keep that in the back of your mind that there is a reason that we're doing that. And then I'm also going to go ahead and set the width of that to 100%. Now why am I doing that? Remember when I told you earlier that floated elements tend to sort of shrink wrap to their content? A normal block-level element would expand to fit its parent container.

But for floated elements, unless you define a width for that element, it tends to vary based on where it is found. So I'm going to go ahead and define a width of 100% on that. I'm going to save that, go back into my browser, refresh the page. The bar there changes color from that sort of darker brown orange to the brighter orange. Now what's happening here? Well, these elements are nested, so the nav element is the parent element, the unordered list is inside of that, list items are inside of that and then finally the links are inside of that.

The way that that's painted on the screen is the parent element is painted first. So if you will, the nav element's behind the unordered list, and since they're both the same size right now, 2 ems, they're laying right one on top of each other, but we're going to change that. Let's go back into our code, and I want to go back up to the nav element, and I'm going to add another property to that, and I'm going to add height to it, and I'm going to give it a height of 2.3 ems. So, as you can see, that is 0.3 ems taller than the unordered list.

Essentially, what we're doing is we are defining heights for both of these guys so that a little bit of the nav element will be showing through or underneath the unordered list, because it will be just a little bit taller. So in essence, this time we're using a line height, not so much to define the overall height of this particular menu bar, but to center the text within a certain area or region. So I'm going to save this, go back into my browser, and refresh that, and there you go, that's exactly what we're looking for. We've got that two-toned bar now, we have got a little bit of that brown sticking out underneath it, and we have the orange on top of it.

I know there's some of you out there right now that are saying, well, why didn't you just go ahead and use a border for the bottom of that in that brown bar, wouldn't have that been a little easier? It probably would have been easier, but one of the things I wanted to show you guys was that you can use all of these different elements as styling hooks. You have this nav element or div, if you're going to put a parent element on your menus, you have that element. It's available for you to style. You also have the unordered list, you also have the individual list items and the links, and in sort of layering these, you can create some really complex structures to your menus.

You could combine gradients, you could combine images and icons with backgrounds. You can have certain backgrounds that are a little bit see-through when others that aren't so. You can do some really powerful things, and I wanted to demonstrate that. Plus, we're going to be doing some rollovers in a moment. They are going to take advantage of the fact that the unordered list is a little shorter than the actual nav element itself. Well, that has got us almost finished, believe it or not. The majority of our menu styling is complete. All that is left for us to do is to create the rollovers, then after that we're going to tackle an optional technique of indicating the current page for menu.

Show transcript

This video is part of

Image for CSS: Styling Navigation
CSS: Styling Navigation

53 video lessons · 17853 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.

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.