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

Start learning with our library of video tutorials taught by experts. Get started

CSS: Styling Navigation
Illustration by

Defining link dimensions


From:

CSS: Styling Navigation

with James Williamson

Video: Defining link dimensions

One of the most important properties of any menu is the dimensions of the actual links themselves. This creates the clickable area that users interact with when they select them. You want to make sure that you create a clear , active area without using too much or too little space. So in this exercise, let's examine a few of the ways that we can define link dimensions. Now, before we get into actually defining them, I want to show you what the current link dimensions are. So I am going to go ahead and open up vertical.htm from the 03_02 folder--that's really just sort of picking up where we left off in the last exercise--and I want to show you what the size of the current active area of those links.
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

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
CSS: Styling Navigation
5h 14m Beginner Nov 16, 2012

Viewers: in countries Watching now:

Join James Williamson, as he shows you how to create elegant menus, links, and buttons that help visitors navigate your site faster and more intuitively. The course covers creating structured navigation that is accessible and clean, styling links, and building horizontal and vertical menus with rollover effects. The last chapter reveals how to create stylish buttons with special effects and CSS sprites.

Topics include:
  • Organizing menus with lists
  • Creating block-level links
  • Styling links, link states, and image links
  • Defining link dimensions
  • Controlling link spacing in a menu
  • Creating rollovers
  • Clearing floats
  • Indicating current pages
  • Controlling cursor states
  • Building dropdown menus
  • Creating CSS-only buttons
Subjects:
Developer Web Web Design Web Development
Software:
CSS
Author:
James Williamson

Defining link dimensions

One of the most important properties of any menu is the dimensions of the actual links themselves. This creates the clickable area that users interact with when they select them. You want to make sure that you create a clear , active area without using too much or too little space. So in this exercise, let's examine a few of the ways that we can define link dimensions. Now, before we get into actually defining them, I want to show you what the current link dimensions are. So I am going to go ahead and open up vertical.htm from the 03_02 folder--that's really just sort of picking up where we left off in the last exercise--and I want to show you what the size of the current active area of those links.

So I am just going to click somewhere on the page, and hit Tab to be able to tab through those links. Now you can see that right now the only area that's active is the content itself, and this is basically due to the inline nature of the anchor element. The anchor tag or the anchor element is an inline level element, and what that basically means is it sort of shrink-wraps itself to the content that's inside of it. So if we want that clickable area, that active area to be a little bit larger--which we certainly do within a menu--we are going to need to be able to define those areas with a little bit more precision, and the first thing we are going to do to do that is to change the display property of those links.

So I am going to go back into my code editor, I am going to scroll down and find the existing vertical menu styles that we have, go ahead and create another selector. Now, this time I am going to create the li a selector. So, now I'm only targeting links when they are found within a list item. So again, that's not going to be global for all the links on my site, just ones that are found inside of a list item. Now again, you know, if we were being a little bit more specific with the menu, we may go in and actually use an ID or a class to help us identify this. Right now we are just staying fairly generic with our selectors.

Okay, so the first property I am going to go ahead and set is the display property, and I am going to change display from inline to block. So essentially what that does is it tells every single one of these links that they need to display as a block-level element, so if I save the file, go back into my browser, and refresh the page, now as I tab through, you see there's a big difference in the clickable area of the link. Now the reason for that is that block-level elements by default are going to stretch to fit the width of the container that they're inside of.

In this case, both the list item which is block-level stretching out, the unordered list is also block-level, and it's stretching out and so that allows the link which is now block-level inside that to stretch out as well, and they are stretching out all the way to the edge of the body element. So they are really just stretching out until they find a parent with a fixed set of dimensions. So now the clickable area of these links actually extends, and you can even see if I hover over on this side, it extends all the way out to the edge of the page. That's useful because you don't want to make people hover over just the text, you want to give them a little bit of grayish area, obviously, if they are mousing over a menu.

But you probably didn't want to stretch for the entire length of the page in this case either. So the next thing we need to do is we need to go in and set a width for these elements. Now, you can do this on one of the parent elements, so it would be fine to go in and take the unordered list tag for example and set a width on that. But in this case, we are just going to keep the styling directly on the link. So after display block, I am going to hit Return to get onto the next line, and I am going to type in width, and I am going to make that width 8 ems. Now I will save that, go back to my browser, refresh the page, and now as I tab through to begin, you can see that they are much more defined in terms of the area that they are inside of.

So, now if I mouse in this area out to the right of it, I am not activating them, only when I come into the area that I wanted for this particular menu are, they going to activate. And notice, they are activating all the way across, even if the text isn't stretched across, which is perfect, that's exactly what I was wanting for that. So I am going to go back to my code, and I want to do one more thing as well. I noticed, for example, that we were able to stretch the width out, but we didn't do anything about the height, the height is still being defined by the contents of these links. In that case, again, we are down to using the actual text of the links to define the height.

So just the same way you can define width, you can define height, so if I go down to the next line, and I type in height, I can set that to say 2 ems, and I'll save that, come back in, we'll refresh that page in the browser. Now it looks like I'm giving them a little bit of extra spacing, but I'm really not. If I tab through them again, you can see that they are still butting right up against each other, they are just a little bit taller, and at this point at 2 ems' worth of height. You may be wondering, why I am using ems instead of pixels or some other unit of measurement? It really depends on what you're working on and how you're working.

If it's a flexible layout, meaning that you have designed it to flex based upon the size of the browser or the size of the screen that you are viewing it on, then ems are a perfect solution for that. So if somebody says we are to increase the size of the text, you'll notice that the relationship between the menu and the text itself remains and they're not shrinking down or getting overly large, they are just staying the same relative size, which is pretty nice. That's going to be very helpful if this is viewed on say a mobile device because the menu will just shrink down to fit basically on the size of the text. So that's one of the reasons why I am using ems here.

You are not required to use ems, it's really just a personal preference. Now, one more thing you'll notice, again, as I tab through these that the text isn't centered in any way shape or form. I mean, it's sort of butting up against the top of the element. And we use the height property to set that, but I think you will very rarely find yourself actually using the height property. I wanted to show you that that you could certainly do that once you have changed them to block- level links, and the fact of the matter is there are other ways to control the height of those elements that do more things for you, for example, vertically aligning the text, so a little bit later on in the chapter we'll see some of those techniques as well.

So, yeah, I know the links there are not much to look at quite yet, but we do have some clearly-defined link regions, and that's something that you want to sort of get out of the way before you begin worrying about the actual presentation of the links themselves.

There are currently no FAQs about CSS: Styling Navigation.

 
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.
Upgrade now


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 Upgrade now

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

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.