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

Creating block-level links

From: HTML5: Structure, Syntax, and Semantics

Video: Creating block-level links

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.

Creating block-level links

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.

Show transcript

This video is part of

Image for HTML5: Structure, Syntax, and Semantics
HTML5: Structure, Syntax, and Semantics

46 video lessons · 39113 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 2m 20s
    1. Welcome
      48s
    2. Using the exercise files
      1m 32s
  2. 18m 41s
    1. A brief overview of HTML5
      3m 57s
    2. What's in the HTML5 specification?
      8m 17s
    3. Why do we need new structural elements?
      6m 27s
  3. 50m 33s
    1. Defining HTML5 documents
      5m 5s
    2. HTML5 syntax
      9m 14s
    3. The header element
      5m 22s
    4. The nav element
      4m 55s
    5. The section element
      4m 51s
    6. The article element
      4m 48s
    7. The aside element
      4m 13s
    8. The footer element
      4m 17s
    9. Content model overview
      7m 48s
  4. 35m 28s
    1. Understanding the outline algorithm
      3m 17s
    2. Creating document sections
      8m 25s
    3. Using headings properly
      9m 1s
    4. Using hgroup to override sectioning
      4m 17s
    5. Properly nesting structure
      7m 17s
    6. Sectioning roots
      3m 11s
  5. 58m 30s
    1. Organizing content
      4m 41s
    2. Planning document structure
      5m 47s
    3. Choosing the right structural element
      4m 43s
    4. Checking document outlines
      5m 27s
    5. Coding initial page structure
      5m 28s
    6. Using class and ID attributes
      5m 31s
    7. Structuring headers
      13m 13s
    8. Building navigation
      7m 1s
    9. Structuring footers
      6m 39s
  6. 1h 27m
    1. Working with figure and figcaption
      7m 12s
    2. Grouping content with asides
      3m 46s
    3. Using divs in HTML5
      5m 0s
    4. Working with lists in HTML5
      7m 10s
    5. The return of bold and italic
      5m 52s
    6. Citing works semantically
      6m 32s
    7. Using the address element
      5m 24s
    8. Using the small element
      4m 24s
    9. Using the mark element
      5m 16s
    10. Working with date and time
      11m 55s
    11. Creating block-level links
      8m 53s
    12. Understanding link relationships
      9m 28s
    13. Defining link relationships
      6m 23s
  7. 17m 22s
    1. Current browser support
      7m 38s
    2. Ensuring block-level display
      4m 3s
    3. Adding support for elements in older browsers
      5m 41s
  8. 3m 46s
    1. Additional Resources
      3m 46s

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


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 Already a member? Log in

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 HTML5: Structure, Syntax, and Semantics.

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 preferences from 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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

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.