Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
Gain a deeper understanding of HTML5 and learn how to create richer, more meaningful web pages with structural tags and descriptive attributes. In this course, author James Williamson presents an overview of HTML5 and its development, defines the new tags and attributes, and discusses how browsers parse and display HTML5 content. The course also includes step-by-step instructions for constructing an HTML5 document with a header and footer, navigation, content groups, and formatting.
One of the really interesting things about reading specifications is going through and seeing what's been added, removed, or changed from previous elements. It's sometimes really surprising what you'll find. Take the link tag, for example. Now I'm sure you've been using the a, or anchor, tag for as long as you've been doing web design. We use it so much in fact that I doubt many people really ever give it much thought. However, if we look at the specification and once again, here I am in the HTML5 spec, the author view and I'm navigated down to the Anchor element.
But if we scroll through all this usual stuff, we're going to find this little gem right down here: "The a element may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content," like buttons or other links. And then they go on to give you an example of this. Now this means that links can now wrap around multiple elements, in effect creating block-level links.
So if you had an introductory section that linked to a larger article, you could wrap the entire section in a link, making it really simple for the reader to click and read the rest of the article and saving you from having to create a lot of duplicate links. All right, so there are some pros and cons to this and some things you really need to think about if you're going to use them, so let's go ahead and flip back into our code and take a look at how this works. Okay, so I'm back in our trails.html file, and this one you can find in the 05_11 folder.
And what I want to do is I want to focus on an area of the page that could benefit perhaps from using these so called block-level links. I'm going to scroll down to our ad copy, and I can find that all the way down here towards the bottom--it's this aside we've got down here on about line 136. Now if I look at this page in the browser and I scroll down, you can see that we have Want to take a tour? We have the logo, the Cycle California logo, and a subheading that says, "Come ride with us!" Now what I want to do is I want to make not only the image clickable, but I also want to make the Come ride with us! clickable as well, so that somebody could go out and browse through all the Cycle California tours by clicking either of those elements.
In the past, we would have to create separate links for that. But now with block-level links, we can just use one link tag to do both of those things for us. Okay, so back inside of our code, we need to find those elements. The first one is our image right here on line 138. So the first thing I'm going to do is just go ahead and open up an anchor tag here. So we're going to do a, we'll do href, and what we're going to do is we're going to link out to the external Explore California site. So we're going to do http://www.explorecalifornia.org, and give it a title, and the title for this one is going to be Check out our tours.
Then I'm just going to go ahead and close the first part of the anchor tag. Now normally, I'd want to wrap the entire image, but this time, I'm going to go all the way down to this paragraph, the Come ride with us! in it is well, and I'm just going to go ahead and close the link tag there. So I'm going to go ahead and save this, and let's check this out in our browser to see if we were successful. I'm just going to go ahead and scroll down, and as we hover over our image, we can see that that link is now working, going out to the Explore California web site.
If I click on Come ride with us! I notice it does as well. As a matter of fact, Firefox is showing us, when we navigate back to our page, based on the focused links it's kind of showing us that both of those are activated by clicking on either of them. That actually showcases one of the things that as a designer you're going to need to think about if you're going to use this technique. Now, this actually isn't really anything brand spanking new. It's new to the specification; this was not in the HTML 4 specification. But browsers have been more or less allowing this for years.
And there have been some designers that have done this from time to time as just kind of a trick knowing that browsers would go ahead and implement it anyway. So the specification is really just sort of reflecting how some browsers have been working for some time now. Now as a designer, there are several things that you need to really think about before you employ this technique. One is your styling. You'll notice that clicking on one of the elements sort of brings the focus to the other ones. So if you have any styles that are based on active links, obviously invoking one area is going to change the styling on the other one.
Hovers, for example, if had a background color that was part of any type of hover style, you would see the background show up behind both of these elements instead of just one. So you have to be very, very careful about how you style these. There are some other styling considerations you need to do as well. So what I want to do is I want to go back to our page, open up the CSS, and modify that CSS slightly. Okay, so here I am back in our code, and what I need you to do is open up the main.css file. You'll find that in the 05_11/_css folder.
All right, now once you have that open, go ahead and scroll down to about line 346 or so, somewhere around in that range, and you should find a comment that says ad copy link styles go here. That's where we're going to be modifying our code. All right, so the first thing I'm going to do is style the sort of subheading text. And I'm just going to write a selector that is aside#adCopy strong, and what we're going to do for that selector is we're going to change the font size.
So let's make the font-size 1.2 ems. I'm going to change the color. I'm going to make the color #952, which is actually the same color as our hover links, and it's just sort of indicating to the individual that this is something clickable. This is a color that they'll recognize as belonging to our links. The next thing I want to do is font- weight, and we'll do just normal for that. Since this is wrapped inside of a strong tag, it's typically bolded. So we want to go ahead and make that normal.
I'm going to do something that I don't believe I've ever done before. I'm going to take text-decoration property and I'm going to force an underline. I've spent my entire career as a designer removing the underline decoration from links. But this time I'm adding it because I want people to know this is clickable, specifically since I'm not doing any hover styling for this particular one. Because hover styling, when you deal with these block-level links, can sometimes cause really undesirable changes to multiple elements. So in this case, I really don't want anything to happen to the image when I hover over the text, so I'm not going to do any hover styling.
All right and finally, we need to do one thing that you'll need to do every single time you use this technique. So regardless of how you style any of the other visual elements that are involved in the block-level links, this is something that you need to make sure you do each and every time you use this. So I'm going to do aside#adCopy a. Now I'm using this to target any link inside of that particular side, because I know there's only going to be one link. So you just need to be very careful about how you target this particular style. What I'm going to do here is I'm going to change the display property of that to block.
Now you'll notice that most browsers-- well, all browsers really--treat the anchor tag as an inline-level element, and that's just natural and normal. So when you take an inline-level element and you wrap that around block-level elements, it can cause some real styling problems in certain browsers. So by going ahead and targeting any link that you're going to do that to, changing its display property to block, you're saving yourself a lot of headache. So you want to make sure that you do that. Now before we move on, I need to point out one more issue as well.
So let me just save this. I want to preview it in the browser again, so we could see our changes. And you can see they're not huge changes. We've just got our underlined text and no hovering going on, so it looks and behaves exactly the way we want it to. Now on to that one more issue that I wanted to bring up. If you wrap the anchor tag around any of the new sectional elements in HTML5, so that be the aside or the nav, the article, and the section element, some browsers, most notably Firefox, tend to have problems properly representing those elements within the DOM.
Elements just tend to get jumbled up all over the place. Now I haven't noticed the issue in Firefox 4, but I don't want to suggest it's fixed just yet without further testing. So one suggested fix is to go ahead and wrap those elements inside the anchor in a div tag, which often will go ahead and solve that problem. So my advice long term is to test this technique thoroughly in all of your target browsers to make sure the elements act and are styled as expected.
There are currently no FAQs about HTML5: Structure, Syntax, and Semantics.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.