Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
While linking to other pages is usually the norm, there are times when you need to link to places within the same page. Usability is an important consideration when designing websites. Although, people will generally tolerate scrolling okay if you can give them away to skip the scrolling and jump right to the information that they're looking for, they're going to be much happier users of your site. Well, that's where named anchors come in. Well, named anchors are aptly named, because instead of the way that the HREF attribute is normally resolved, links to named anchors reference instead an ID value allowing you to link to any element on the page that has a specific ID attribute.
Let's see how we can use that to enhance our navigation on the Frequently Asked Questions page, just to kind of show you give me an idea of what we were talking about here. I'm going to and preview this page in a browser. Well, you can see that we have a lot of questions here and it takes a little bit of time to scroll down through it. Now this page honestly is not that long; I've seen pages a lot longer than this, but the fact of the matter is if I could help somebody out and all they were interested in for example what say Financial Aid allowing them to jump to this section is actually quite helpful.
So that's what we're going to be doing here. I'm going to go ahead and close my browser, go back into Dreamweaver, and anytime that you're going to be using named anchors on the page there's actually kind of a two-step process. The first part of it is to make sure that you have the IDs assigned to the elements that you're going to jump to. So that's what we're going to do first off. So I'm just going to go ahead and click inside this headline for Common Questions and right there on the Properties Inspector we can go ahead and assign IDs. So this is very quick and very easy. I'm going to go ahead and assign this in ID of the top. Another thing that usability is if you're going to give people the ability to jump down to the bottom of the page, you really ought to give them the ability to jump back up as well so they don't have to scroll back.
Now I'm going to continue scroll down through the page and I can see that I have sections for Housing, Portfolio Review, Financial Aid, and Programs. So I'm going to click inside Housing and I'm going to give it an ID of, you guessed it, housing. Now it's a good idea to keep these IDs as short as you can, makes it easier for you to remember and resolve them. You also don't want to use any special characters or any spaces in IDs. IDs need to be one single word. For Portfolio I'm just going to do Portfolio and for Financial Aid I'm going to click inside that headline, and I'm just going to call that one aid and then finally for Programs I'm going to call that one programs. There we go! That was easy enough.
So I'm going to Save that and what we've really done is we've assigned an ID attribute. Now if I look at tag selector right now I can see the Dreamweaver is representing this is h2#program. Now up until now we've really been looking at a lot of classes which use a period to represent themselves, but for IDs the Pound symbol is used. So when we're resolving this link we're going to link to the Pound symbol and then whatever the name of the ID attribute is. So I'm going to scroll back up and we're going to start making our links. I'm going to highlight the text Housing right here and then in the Link dialog box I'm just going to link that to # housing, so I don't need to put any specific document in there or any type of path of the document.
All I need to do, since this is on the same page, is just give the ID of the element that I want to navigate to. I'm just going to continue to do this for each one of these guys. For Portfolio Review I'm just going to do #portfolio. For Financial Aid I'm just going to do #aid, and for Programs, you guessed it #programs. Now you've got to remember the pound symbol. If you don't use that of course your link is not going to resolve.
Now we also have these links right here that will take people back to the top of the page. So that's going to use the first ID with that we created which is #top. Now once you've typed one of these in, remember Dreamweaver has a memory of that. So when I highlight the next line of text that I want to link this to, I can just go right at the top, link it to that and I am good to go. I'm just going to continue to do this for each one of these. So it really doesn't take a lot of time, you can knock these out pretty quickly once you get started on them. So now I'm going to Save this and preview this in my browser.
So now we've set our links at the top, and if I click on Portfolio Review you can see that I jump down to Portfolio. Clicking the Back button will take me back at the top of the page. Now there's one I wanted to list. If I click on Programs for example you'll notice program doesn't quite make it all the way up to the top. And that's basically because there's no room left at the bottom of the page. So as it gets closer to the bottom it's going to stop when it runs out of content down here. Now it is also possible to link to named anchors on separate pages. If I go back into Dreamweaver I can switch over to the Programs page. Now the Programs page is found in the Programs directory whereas the FAQ page is found in the Admissions directory.
Well, if I scroll down I can see that right here I have Please contact the department chair(s) for more information, or view our FAQ on programs. So obviously the only part people here might be interested in is just the section on Programs. So if I highlight this text; I'm going to show you a cool little feature in Dreamweaver. Now obviously I could type in this link and resolve it, but if you aren't just sort of insure exactly what the path is going to be, because we're going upper directory in and down into another directory and if you're kind of unsure how to type that notice that we can go up to the top; I've got both of these documents open at the exact same time, I can go up to the menu and I can go to Window, and I can choose Tile Horizontally or Tile Vertically and what that's going to do is it's going to take the pages that I have open and it's going to put them side by side.
So in this case I'm saying Tile Vertically. Well, what I can do now is I can just sort of scroll to the element on the page that I want to link to. So now I can highlight this FAQ, and I can use the Point of File icon to point to this element on the page. Check out what's being done in the Link dialog box right now. It's resolving this link as ../ meaning go up a folder, admissions go into the Admissions folder, faq.htm and with no spaces #programs. So that's how we resolve name anchor links that are found on other pages.
We just resolve the link as we would normally and then we place the ID right on the end of it. I'm going to let go of that now. I'm going to do a Save All and now if I test my Programs page in the browser, I notice if I scroll down and click on the FAQ, not only does it take me to the Frequently Asked Question page it takes me to that specific region on the page that I was looking for. Now obviously not every page is going to need named anchors. However, when your data requires a lot of scrolling or if you just like to give people quick access to specific locations, named anchors allow you to add a lot of functionality to your sites.
Get unlimited access to all courses for just $25/month.Become a member