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

Styling block-level links

From: CSS: Styling Navigation

Video: Styling block-level links

While the addition of block-level links has given us more flexibility when structuring our pages, it does present us with certain styling challenges. In this exercise I want to dig a little deeper into styling these block-level linked regions. And we talked about these earlier way back in Chapter 1, I am going to start talking about some of those styling issues that you need to consider if you want to use block level link regions in your own files. So I have a block-level.htm file open in the 06_06 folder, and the first thing I am going to do is just preview this in a browser so you can see what's was going on just sort of a way of refreshing your memory.

Styling block-level links

While the addition of block-level links has given us more flexibility when structuring our pages, it does present us with certain styling challenges. In this exercise I want to dig a little deeper into styling these block-level linked regions. And we talked about these earlier way back in Chapter 1, I am going to start talking about some of those styling issues that you need to consider if you want to use block level link regions in your own files. So I have a block-level.htm file open in the 06_06 folder, and the first thing I am going to do is just preview this in a browser so you can see what's was going on just sort of a way of refreshing your memory.

So we have this product detail region, and there is a link tag wrapped around the h2, the image, the paragraph down here, and you see when I hover over one item all of the other items get its styling, and that's the biggest problem that you're going to run into with these block-level links. Everything inside of it shares the link state, so if I click, for example, everything gets its active state. If I focus on it, everything gets the focus state of it. So it's one of those things where you have to be very, very careful about how you style it, and you have to be very, very careful about how styles are inherited.

So I am going to go back into the block-level, and just to refresh your memory on the structure of this, notice that we have a link element, it has a class of detail, it also has a class of, and if you remember from earlier when we are applying a clear fix to it, that should give you some ideas what's going to happen inside of this anyway. Then we have a couple paragraphs, an image and an h2, all surrounded by that link. Okay, let's go up and start styling this. So I am just going to start in my block-level styles, and since that anchor element is sort of a parent tag the same way that sometimes div tags or section tags are parent tags, I'd really like to sort of style that into a very distinct region.

So I am going to take the class that we've applied to that link, which is detail, I am just going to give it some styling. So the first thing I am going to do is I am going to say, okay, I would like the width of that to be 600 pixels, so again, I am going to make it a very distinct region. I am going to give it some padding, and I'll give it a padding of 20 pixels all the way around. I am going to set the line-height for all the text inside of it to 1.4. I am going to give it a background, and I am just going to give it a background color. So I am going to do rgb (184, 205, 205), which is a light blue--and no, I don't have those memorized-- and then a border of 4 pixels, so a big border around this, solid, and then another RGB color there, here we'll do a little bit of darker blue, 91, 123, 164.

So if we were styling a div tag right now--I need to go ahead and close my curly bracket there--but if we were styling a div tag right now or a section, these are box model properties that are going to clearly define that region. But since this is a block-level link, let's see how this works. So I am going to save this, go back into my browser, and refresh it, and well, that didn't work at all. I can see some of the styling there, but it's not what I was looking for at all. Now the reason for that is that even though you've wrapped block-level elements with an anchor element to the browser, the anchor element is still an inline element.

So what it's doing is it's creating these inline boxes sort of wrapping them around each one of the block- level elements inside of it. So in order to get around that, it's actually a pretty simple fix. We just come into the detail selector that we just created, and we tell the link that we want it to display as a block-level element. So saving that, previewing it, and hey cool, now we are getting that sort of defined region that we want. Okay, so now we can go inside that region to start styling some of those interior elements.

So .detail h2, and inside that I'm going to do a font-size of 1.6 ems, and I am just going to do margin-top of 0, and that's just going to strip out any default margin there. The next thing I am going to do I am going to tackle the image. So I am going to say .detail img, and don't forget the period in front of detail. Remember, it is a class selector, and for that I'm going to do a float to the left, and that's going to wrap the text around an image, and I am going to do a margin right of 1 em, and it's going to hold the text off that image.

Now, that's the reason that I have that clear fix on class applied to that link. That way, it will contain this image and not let the image overflows the contents. All right, I am going to go ahead and save that, go back and refresh that, and that's starting to look a little bit better. Now, there are still some things that I want to do with this, maybe I don't like the color of the paragraph text, maybe I would like the price to be styled a little bit different, and also I notice that when I hover over anywhere in the link everything still gets the hover styling applied to them, so we re still going to need to deal with that too. Underneath .detail image, I am going to do .detail p, and with that I am going to do a color.

So I am going to change the color of this. I am going to do rgb and the color that I am going to give this is 54, 64, 75. So it's kind of darker blue, still blue though. Underneath that I am going to change the font size, I am going to make the font size a little bit bigger, it's a separate defined region, so I am going to make the font size a little bit bigger of 1.2 ems. I am going to follow that with the price. Now I didn't point this out to you earlier, but that one paragraph down there, that price is inside of I actually applied a class of price to it as well.

So I am going to say .detail .price to target that piece of text, and inside that I want to change its font-size to 1.6 ems. So I am going to make it larger, I am going to change its font-weight to bold, I want to apply a text-align to the right so it aligns to the right of our defined region, and finally, I am going to turn the margin-bottom off so that it doesn't stretch our detail region down. So I am going to save that, preview it, and that's looking a lot better.

But I still have this hover effect that is applying to my default links, but I don't really want it to apply here. So the very next thing I am going to do is go down and strip out that, and I can do that at sort of a top level, if you will. I am going to say .detail hover. I am going to use the hover pseudo class selector, and I am going to attach it to the class of detail, no space in between them obviously. Here I am going to turn the text-declaration underline, I am going to turn that off by saying none. I am going to set a background color. So remember this is the whole background of the entire region. I am going to change it to a lighter blue, #C885F0.

So here I am mixing HEX values and RGB, three values together again, and I am also going to do that with the border. So I am going to do border-color, not the entire border property, but just the border-color property. I am going to do RGB, and inside that I am going to do 36, 54, 70, so it's a much darker blue, and it's going to make the border really stand out when somebody hovers over that. All right, so I am going to go ahead and save that, go back, refresh, and now instead of getting an underline, I get that nice rollover effect of that lighter blue in the border.

And what's really nice about that again is it tells in a very subtle way that, hey, this entire region is clickable, so you've got that the whole region that's a clickable region, and I don't have anything going on with any of the text. Now that's not to say that you can't, if you wanted the text--either the heading text or the paragraph text--to change or have a rollover effect on that as well, you could certainly do that. Let me show you really quickly how to do that. Let's say for example I come in and write one more selector. I could do .detail h2:hover and then another comma, and I could say .detail p:hover.

So remember, the hover pseudo-class selector can be used on things other links. So I am going to target the h2 and the p directly, and I will just change their color as well, and this time I am going to use the #916226, so sort of that brown color. I will go ahead and save that, preview the page, there's our finished region. Not only does the whole thing light up whenever I mouse over, but if I mouse over the text, it gives even another little signal that, hey, this is all clickable by changing the color of the text as rollovers as well.

Now, you want to be careful about mixing too many things like that, because you might send mixed messages. A person might assume that this is clickable, but they might also assume that this goes to a totally separate page. So you really want to think in terms of usability and user experience of that. Really, most important thing that you want to remember if you're dealing with these block- level links, the link itself is still going to behave like an inline element unless you specify it otherwise, like we did with the block-level display. And you also need to remember to overwrite all of the global link styles to ensure that any unwanted styling doesn't appear somewhere within the link, and sometimes it's awful hard to read out those individual properties.

Show transcript

This video is part of

Image for CSS: Styling Navigation
CSS: Styling Navigation

53 video lessons · 16655 viewers

James Williamson
Author

 
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

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

Your file was successfully uploaded.

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.