New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

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

Restricting link styling

From: CSS: Styling Navigation

Video: Restricting link styling

We are almost finished with our menu, but we have one little bit of housekeeping to do before we are totally done. You may have noticed that all of our links have a bottom-border, including this last one. Since the border's function is to provide visual separation between the links, it really doesn't belong on this last menu item. You are going to run into this problem over and over again when you're styling menus. Regardless of whether it's a horizontal or a vertical menu, you're bound to have some extra padding, margins, borders, or some other property on either the first or last menu item, sometimes both.

Restricting link styling

We are almost finished with our menu, but we have one little bit of housekeeping to do before we are totally done. You may have noticed that all of our links have a bottom-border, including this last one. Since the border's function is to provide visual separation between the links, it really doesn't belong on this last menu item. You are going to run into this problem over and over again when you're styling menus. Regardless of whether it's a horizontal or a vertical menu, you're bound to have some extra padding, margins, borders, or some other property on either the first or last menu item, sometimes both.

In a lot of cases, that won't be that big of a deal, but for others, it really might be the difference between the menu actually fitting within the layout or it actually working or not. Let's see how we can clean that up. Now, before I jump into the code and start working with our file, I want to take you over to the W3C's Selectors Level 3 specification. And we are just focusing on one small section of it, and this is a little rundown of all of the different selectors. I just want to point out a couple of these that can be extremely helpful when you're trying to target the first or last element within a structure.

So, we have the first-child and last-child selectors. We have first-of-type and last-of-type. We also have only and only-of-type, but they are not really that useful for us for menus. Then we have these nth selectors, which are a little bit more complex. But these guys right here, first-child, last-child, first-of-type, and last-of-type, those can be extremely helpful when you are dealing with a menu, and you need to select the first menu item, or the last menu item and change the styling or restrict the styling in some way. Notice that those are pseudo-class selectors, exactly the same as hover and active and focus, and those types of things.

So, very easy to use, we're familiar with using hover. And these selectors are the ones particular that I'm talking about actually enjoy pretty widespread support among browsers. So, I am going to go back into my code editor, and I am just going to scroll down all the way to the bottom of our CSS, and I just need to create one more selector. So, I am going to go down and create a little empty space here, and I am going to type in li:last-child a. So, think about what this is actually doing is it's saying, hey, go into the page, find all of the list times.

The list items that are the last child of their list, meaning the last one in the list I want you to find and target the anchor, or the link tags inside of that. So it's a very nice, easy way to do that without having to go down into your list and apply classes to them, which is what we used to have to do before we had the selectors available to us. And all we have to do inside this selector-- it's very easy--we just need to tell it for the border-bottom that we want none. So, I am going to go ahead and save that, go back out to my browser, and just refresh the page.

And sure enough, our last menu item no longer has that border. And that's it, here is our finished vertical menu. It's a very simple menu. But the core techniques that you've learned here can be expanded to create more complex visual menus. Keep this last technique handy, as you're going to need to restrict styling in some way, in almost every single menu you create. Feel free to experiment with this menu, modify the styling and see what you can come up with. Once you are comfortable with the steps that I've outlined in this chapter, be sure to check out this chapter's lab, and put your new skills to the test.

Show transcript

This video is part of

Image for CSS: Styling Navigation
CSS: Styling Navigation

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

Are you sure you want to delete this note?

No

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.