We launched a new IT training category! Check out the 140+ courses now.

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

Styling image links

From: CSS: Styling Navigation

Video: Styling image links

Occasionally, you are going to need an image that's also a clickable link. Although most link styling considerations also apply to images as well, there are a couple of things that you are going to want to be aware of as you're styling image links. So to show off some of those things, I'm going to work on the image.htm file that you can find in the 02_05 folder. I have got that opened up currently in a browser, so you can sort of see what this page is all about. We have a larger image up top that is a clickable link, and then we have some thumbnails down here in the bottom that are also all individually clickable. Now, you can see that this browser--which is Opera-- doesn't really have any default image link styling.

Styling image links

Occasionally, you are going to need an image that's also a clickable link. Although most link styling considerations also apply to images as well, there are a couple of things that you are going to want to be aware of as you're styling image links. So to show off some of those things, I'm going to work on the image.htm file that you can find in the 02_05 folder. I have got that opened up currently in a browser, so you can sort of see what this page is all about. We have a larger image up top that is a clickable link, and then we have some thumbnails down here in the bottom that are also all individually clickable. Now, you can see that this browser--which is Opera-- doesn't really have any default image link styling.

So, when I make an image also a link by wrapping it an anchor element, there really isn't any default styling. The only indication I get is the little hand that shows up, the cursor changes to let me know that it's clickable. In older browsers, you would often see sort of a default blue border show up on the image which a lot of designers found undesirable. So, for the most part, modern browsers don't really have any default styling cues that an image is also a link. But if somebody is viewing this in an older browser, you might have a really obnoxious blue border around the image right now.

So, one of the first things that most designers do is they strip out any of that sort of default styling. So, I'm going to go into my code editor where I have the image file opened as well. I am going to scroll down to the bottom of my styles. I have a little indicator there for image styles. I am just going to go ahead and create a default selector here for any images that are also links. So, I am going to do a img, and it's going to say any image that's inside of an anchor element. The only property I am going to set in there right now is border: none. Now, that's going to make absolutely no difference to the page that I have opened in the browser right now.

The only thing that, that would effect is older browsers that sort of show that default blue link. But what if I really did want some way to indicate to the user that this is clickable and something maybe a little bit more robust than just a cursor changing only? In order to do that, I can take advantage of all the selectors that we've been using in previous exercises. So if I go down right below that and create the selector, that's a:hover, so anytime anchor is hovered over, and then I am going to do space img, which is going to say any image that's inside of an anchor which is being hovered.

So inside that, I'm going to go ahead and set another border, but this time I am going to be a little bit more specific about the border itself. I am going to do 4 pixels solid, and then I am going to set the color to be D5973C. Now, that's actually the same exact color that I am using for links on the page as well for hovering, and that's an important consideration. You want to make sure that you don't deviate from your site's default link styling when you start working with images. Being consistent like that is going to send a much clearer picture to the users of your page.

So, I am going to refresh this, and now as I hover over the image, I can see I get a sort of orange border around it. But there's an unintended side effect here. You'll notice that as I hover over it, everything is shifting just a little bit to the right, including the text, and this can cause real problems in layouts. Now, the reason that this is happening is that borders do add to the overall width and height of an element. So if I suddenly put a border on an element that didn't have one before, all the other content is going to have to shift to make room for it, and that can really cause layouts to break.

So, that's one of the things that you need to think about, and of course, we can sort of modify this a little bit. If I go back into my page, and I change the border: none here to 4 pixels solid and white, save that. Now, what that does for me is it's going to put sort of a default white frame around any images that are also links. And when I highlight that, I skip that nice orange color, but then I have this white border around it, that sort of gives me that nice default frame that's going to cause everything to stay exactly the same and the layouts aren't going to shift.

Now, that's a really nice effect. But if you didn't want that white frame around it, one of the things that you could do is take that border and make it the exact same color as the background. Doing that would basically cause the border to be invisible until somebody hovered over it. Now, at the very bottom of this, I have got some thumbnails down there, and right now they're just basically using the same styling that my image link has up here, and that's fine for the most part. There is nothing wrong with that at all. But there are a lot of things that people do when they style thumbnails. They make them bigger, they rotate them, they animate them, there is all sorts of stuff that you can do.

So, what I want to do is I just want to show you some really basic thumbnail styling so that you can get a feel for it, and then you can take it and expand it and create your own thumbnail styling. All right, so I am going to go back into my code, and one of the things I want to point out, if I scroll down, I can see that each one of these thumbnail images has the class of thumb applied to that, and that's going to allow me to target each one of them. I also want to point out that their width, and height is set to 100 pixels, but the images themselves are actually larger than that. So, what we are doing right now is these thumbnails are being scaled down. The original size of the image is 150x150, but we are scaling them down to 100x100.

Now, the reason I did that is because what I want to have happen is when I mouse over these thumbnails, I want them to get bigger, I want it to get larger. If you do that with an image that you're basically making larger than its original size, it's going to blur the image and really damage the image quality. So, the technique that I am using here is to shrink them down originally, a thumbnail, and then bring them back to their original size as they get larger. Okay, so I am going to go right up to my image styles and just create another selector up here. And what I am going to do is I am just going to create the class thumb selector, and that's going to help me target these thumbnail images.

So, the first thing I want to do is turn off the border that was applied via the a img selector. So I am going to go ahead and turn that border off so that it doesn't have that sort of default white frame. Then I am going to put a little bit of padding up top. I am going to do padding-top: 58 px. Now, the reason I am doing that is because as these get larger, I want them to move kind of up instead of down, and having that padding on top is going to force the thumbnails down originally so that when I remove the padding when they get bigger, they will move up instead of moving them down. Now obviously, if this were in some type of a filmstrip or in a defined region of the page, the region itself would sort of be dictating how I needed to accomplish that.

But since they're sort of off on their own, it's really easy for me to just add a little bit of padding up top. So if I save this, go back into my browser, and refresh that, you can see a couple of things happen here. You can see first, the frame goes away, and the second thing that you can see is that they were pushed down a little bit. So there is a little bit of empty space above them now to allow them to grow. Now, currently, the hover is causing a very unpleasant effect of a large border that goes all the way around, including the padding. And of course, they have to shift a little bit because they don't have a border applied to them by default. All right, so we need to control the hovering of these.

And to do that, I am going to create another selector, I am going to say a .thumb, which of course is the thumb class: hover. So I am saying, hey, when any image or any element for that matter with a class of thumb applied to it, when that's hovered over, and it's inside of a link, let's go ahead and do something else. So, you'll notice that hover can be applied to things other than anchor elements. You can apply it to really any element on the page, and almost all modern browsers will recognize that. All right, so first thing I am going to do is I am going to set padding to 4 pixels. It's going to offset the top padding of 58 pixels, and it's going to create equal padding all the way around that.

Now, the reason for that is I am also going to apply a background color to it, and I am going to do background color of #D5973C. Now, you might recognize that color from up here, it's the same color that we applied to the border. You might also notice that I'm using 4 pixels for the border and 4 pixels for the padding. So, it's going to be visually the same effect, but instead of applying a border, I am going to use padding to give me enough room so that I can see some of the background color sort of poke through, if you will. Now just below that, I am going to set the width to 150 pixels.

Now again, that's going to set it to the original or the actual size of image, and I need to follow through and do the same thing to the height, so now the width and height, they are going to be set to the actual size of the image, which is 150 rather than 100. Then finally for border, I am also going to go ahead and apply none, and that's going to turn off that orange border that you were seeing just a minute ago. So if I save this and go back into my thumbnails and refresh these, now as I hover over them, you can see they get larger. They get what looks to be an orange border around it, but we know it's not, we know it's the background color that's being displayed because of the padding around it, and it's occupying that sort of empty space that we took above it.

So instead of pushing them down, they are allowed to go up and occupy that space above it. That's not the only way to style thumbnails. And for the most part, how you style any of your linked images or control these types of thumbnails is really just a matter of personal preference. Just remember which properties you can control, and if you use any type of a reset in your CSS, you are going to want to remove any default borders for linked images that might exist in some of those older browsers.

Show transcript

This video is part of

Image for CSS: Styling Navigation
CSS: Styling Navigation

53 video lessons · 17403 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 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.

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.