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

Indicating external links


From:

CSS: Styling Navigation

with James Williamson

Video: Indicating external links

Occasionally, you're going to want to indicate when a link is going to redirect a user to an external site, or even download an external resource. Now, the easiest way to do this is to use attribute selectors to the filter out link types. Now, while we're focusing on a specific use case in this particular exercise, I really want you to think about all the different ways that you can use the techniques that I'm going to show you in this exercise to enhance your navigation. There may be you know some other ways that are unexpected. All right, so I have the external.htm page open from the 02_04 folder.
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

Indicating external links

Occasionally, you're going to want to indicate when a link is going to redirect a user to an external site, or even download an external resource. Now, the easiest way to do this is to use attribute selectors to the filter out link types. Now, while we're focusing on a specific use case in this particular exercise, I really want you to think about all the different ways that you can use the techniques that I'm going to show you in this exercise to enhance your navigation. There may be you know some other ways that are unexpected. All right, so I have the external.htm page open from the 02_04 folder.

I just want to show you this in the browser, so I can show you what I'm talking about here. We're indicating external links. We're going to show the user that we when they're going to click on something, it's going to take them outside the site or download a file like Word document or PDF or something of that nature. So I have got four links currently built into this. I've got two of them that are going to take you off the site, so mocked to one that shows off the font that I'm going to be using Modern Pictograms, and the other one that takes you to Font Squirrel where you can find that font. Take a look at these character set.

Then I have an internal link that takes you to a link within the same site, and then I have to an external resource that downloads a Word document. So I really want to distinguish between these different types of links when I'm styling them. Now, the easiest way to do that is to use attribute selectors. So if you've never used attribute selectors before, these are awesome. I'm just going to go right up into this style tag in my code ,and below all of my active selectors, I'm going to go ahead and create a new one. So what I'm going to do is I'm going to go ahead and do an a selector, and then an attribute selector just follows whatever element you're targeting with brackets, so those sort of square brackets.

And I'm just going to type in href and then close my bracket and then go ahead and open up a curly brace, hit Enter twice, and close the curly brace just so I've got my initial selector here, and then I'm just going to change color to red. Okay, so let's talk about the syntax of this. Basically, those brackets right there are saying, hey, I'm targeting an attribute when it's applied to this element. So it's going to say go down to find any anchor element that has an href attribute. So if I save this and go back to my page and refresh that, you can see that it's targeting every single link.

It's targeting every single link because they all have an href attribute. Well, fortunately, we can actually filter that to a greater degree by looking for specific values for attributes. So not only can we look for the href attribute, we can modify this a little bit. I'm going to go ahead and do a caret, which is that upward pointing arrow that you can get by holding down a Shift and 6, and then directly after that I'm going to type in equals. You'll notice that there are no spaces there. It's just that caret-equals. Now what this does is it's saying, okay, take a look at the value of href, and that's the equals sign, but the caret says look for something that starts with.

So it's not looking for the entire value of the href attribute, it's only looking for when it starts with a certain set of characters. Now the next thing you need to do is tell it which characters to look for. So I'm going to open up a quotation mark, and then I'm going to type in http:// and then close my quotation marks. Now, did I really need the forward-slash, forward-slash? No, probably not. I could've probably gotten away with http, but I'm just being thorough. So, essentially what I'm saying now is I'm saying, hey, go out and find any link that has an a href attribute. Find the href attribute that begins with http://.

So now if I save this, go back in, and refresh my page, you can see that now it's only targeting those two links, and that's because they're going to external sites. One is going to a page that details their font Modern Pictograms, and the other one is going to Font Squirrel which is one of my favorite font resources. Well, that's pretty cool, but what we're wanting to do is indicate external links in maybe a more obvious way. Chances are your users aren't going to know that red text indicates an external link unless you tell them somewhere. So we want to really demonstrate that visually, and one of the ways to do that is to use some type of an icon.

Now there are a lot of different ways to do this technique. In lot of tutorials out there, you might see people use background images or even, you know, real images right next to them. Those are good techniques, but the problem that I have with them is they're not really scalable. We live in a time now where fixed size websites really aren't that powerful anymore because people might be viewing it on a phone or different screen size. The user might want to increase the size of the text or decrease the size of the text. And when you start putting fixed size images or icons in your pages like that, they don't scale quite as well.

So one of the things that I really like is the development of what's known as icon fonts. And I'm just going to switch over here to Font Squirrel and show you the font that we're going to be using, which is Modern Pictograms. Now this is by John Caserta, and I hope I'm pronouncing his name right. But he created this one, and it's available, it has an open-source license out here on Font Squirrel. And you can go download this and use it in your own projects. And you can see it has a series of icons here that are mapped to certain characters. So if you want this particular up arrow, for example, you just use that sort of left bracket.

It's really cool, and it's extremely easy to do. The problem is, obviously, I don't want to go through my site and find all of my external links--and by the way, the symbol we're going to be using is right here for the O. This is a pretty common symbol for external links, and that's the one I want to use. Well, I don't want to have to go through all my code and put an O next to all of that. So I'm going to combine the technique of using attribute selector with what's known as generated content. So I'm going to go back into my selector here, and I'm going to modify this selector a little bit, and right after the attribute selector, I'm going to type in :after.

Now what this does is this is generated content that basically says after the content in this selector--which in this case is the anchor element--I want you to put some other content for me, I want you to put something in there. So I'm going to go ahead and modify this a little bit. I'm going to take the color red and get rid of that, and I am going to type in content and then in quotation marks, space and then a lower case O, and that's because that's the character I want to use. And this space that I'm using here is going to give me a little bit of separation between the link and the icon that's going to show up. Now how are we going to use that font? Well, if I go further up in my code, I can see that I'm using it @font-face declaration.

This going to use that modernpics-webfont, and I've actually included the fonts right over here in this fonts directory, so it's pointing to those. So all I need to do in order to use that, now if I scroll down is now I'm going to say font-family, and I'm going to use the definition that I created up top. I'm just going to type in Modern, sans-serif, and below that I can start to modify this a little bit. I'm going to say, okay, I want its font-size to 1.1 ems.

And then I want to move it a little bit, so I'm going to set a position of relative on it, and then I'm going to do a top value of -0.2 ems. Now let me go over each of that line by line to tell you what that's going to do for us. So this content line is going to place that O character to space O after the contents of the link. The font-family is saying I want you to style that using the Modern font, which is going use icon font. The font-size is going to make a little bit larger than the text it's in, and that's okay because it's a really small icon.

And then this position: relative, top: -0.2 ems is going to move it up a little bit so that sort of superscripts that icon. So if I save this, go back at to the browser, and refresh that, you can see now the red text is replaced with that icon, sort of in that upper right-hand corner. Now one of the defects obviously, of this being a icon font and all the styling applying to it, you can see sort of that hover effect is now applying to everything. So in this case, I may want to get rid of that underline so that you don't see it there. So I can go back to my hover, get rid of that text decoration.

These are some of the trade-offs that you need to make when you're thinking that using these types of icon fonts. So you want to really plan thoroughly before you start styling these, you really want to think about them. Now, I mentioned that I have an external resource here. This technique is extremely flexible, and it can work for several different things. If I go back in to my code here and instead of typing all this again, I'm just going to copy this and paste it, and I'm going to change the attribute selector. I want to change the attribute selector from a caret equals to a dollar sign equals. So the caret equals says anything that begins with the string, the dollar sign equals says anything that ends with the string.

Now, since the link to an external document is linking to a Word document, it's pretty easy for me to say, hey, if the href ends with .doc, which would be a Word doc, I want to do something different. In this case, instead of a lowercase O, I'm going to do space and then uppercase K. I don't really need to change this setting because of the formatting, I want to keep that consistent. So, I'm just going to save that, go back out to the browser, and Refresh that. And now you'll notice that I get the little document icon there in addition to the external site document. This is a fairly complex technique.

If you're new to CSS, I could see this being a little bit overwhelming. So just slow it down and go through step by step and really come to understand what each of these things is doing for you. You know, it's important for me that you're not just sort of take away this technique, it's important for you to understand that this is not the only way to target these kind of links or even to display these icons. However, it is one of my favorite techniques, and it illustrates two things that are very important. First, attribute selectors, generated content, and icon fonts. Those three things are very powerful.

And when you combine these techniques, it can be extremely powerful. And second, you really need to think about things like accessibility, screen sizes and how flexible certain techniques are before you use them. One of the reasons why I went so complex with this technique and used icon fonts is if somebody comes in and ups the size of the text, notice that the icons scale right along with that. If I had created, say, a GIF file and used that as a background image, that wouldn't be the case. And somebody increasing and decreasing the size of the text, or even displaying it on a smaller screen like a mobile phone, there would be a really big disconnect between the text and the icon itself.

So those are some of the things you really need to think about. Often it's really just choosing the technique that's the best overall fit for the situation, rather than simply using a single technique for every situation.

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.