Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
This course introduces web designers to the nuts and bolts of HTML (HyperText Markup Language), the programming language used to create web pages. Author Bill Weinman explains what HTML is, how it's structured, and presents the major tags and features of the language. Discover how to format text and lists, add images and flow text around them, link to other pages and sites, embed audio and video, and create HTML forms. Additional tutorials cover the new elements in HTML5, the latest version of HTML, and prepare you to start working with Cascading Style Sheets (CSS).
It's very common to use images as links. Let's look at how this is done. We will make a working copy of links.html. I'm going to call this copy links-working.html and I am going to open this in my editor. You will notice here's a link, and this link is a text link. If I open this in the browser, you will see that it looks just like that, and it's got this little text link. And if I click on that, it takes you to my page on my server. And that's exactly what we would expect.
Now if I change this to an image and do this, img src ="images/paper-small.png," that's a file in our exercise files in the images subdirectory here. And if I save this and take a look at it in the browser, hit Reload, we have this nice little image of a piece of paper from my desk. And you notice that when I hover the mouse over it, the mouse pointer changes into a little cartoons glove hands pointing at something.
And if I click on that, it takes me to the target of our link. So, that's easy enough. There are a couple things we need to know about this though. For example, if I'm being cool and I want to put all of this on separate lines-- maybe my image tag is going to be a little bit long or maybe I just like to organize my code like this-- I would like for that to work, because that actually looks pretty cool to me. So if I reload this in the browser, you'll notice right there, there is a little purple underline, and it would be blue if we hadn't clicked on the link already.
What it is is you remember how HTML handles space, so all of this whitespace here is being folded into one space character and that space character is inside of the link, so it's being underlined as if it were a text link. Because if I were to just type some text here and save that and reload, you see that comes up underlined and in purple, and that becomes part of our link. So instead, what we have here is just this whitespace. Now some browsers will do this; some browsers won't. Some browsers are smart enough to say, oh, you didn't really mean to put a space there.
But fortunately there's a way for us to tell the browser we really didn't mean to put a space there, and that's like this. I take the end of that image tag and I just move it down to the next line and put it right before the . And when I reload the page, our little anomaly is gone. Now it's also possible on some browsers for the other side of the image to get one of those. So I can do the same thing here. I can take that begin tag and I can put it over here, and in fact, some browsers even want the whole opening image.
They don't want a space between that beginning of the angle bracket and the name of the tag. And I can take all of that stuff and I can put it up on that line above, if I want to, and this still works just fine. Now there's another potential problem here, and what I am going to do is I am going to open this in a very old version of Firefox so you can see this. Most modern browsers don't have this problem, but there are still some old browsers out there that do, so you need to be aware of it. So I am going to close Firefox here, and I am going to go ahead and I am going to open this with Firefox 1.5.
Now you'll notice that my image has this whole purple box around it, and in the olden days of the web, that was considered pretty cool, because it meant this is a link and it made it obvious to people that that was link. And today, we mostly don't want that, because frankly, it's ugly, and it doesn't look right. So what I do is I create a style. And in that style, with CSS, I say, "a img" like this, which means all of the image tags that are descendents of a tags will have this style in it, and I say border-style: none, like that.
Now when I reload this, you notice that the little blue box is gone. Now, just so you know--I am going to comment this out and reload and you see our blue box is back-- there is another way to do this. and the other way to do this is with another attribute to the image tag called border ="0" like that. and when I save that and reload it, you will notice that our border is gone. And that's actually the way that we used to do in the days when this browser was current. But this is actually obsoleted by the current HTML5.
On the other hand, if you're looking to support really old browsers, you may come across some really old browsers that don't support CSS, and if you want those to work right, well, then you are going to want to use an older version of HTML, because they probably don't support HTML5 either, and you're going to want to know about this border="0". So border="0," that's the old way that it was done from a HTML4 and before that, but the new way to do it of course is with style sheets. And we use the image tag as descendent of the a tag and simply this border-style: none, and that works just fine.
So using images as links is a very common technique. HTML makes it easy to support this design decision. Be sure to test your code on a number of different platforms and browsers, as there are some potential discrepancies with how the links are rendered.
Find answers to the most frequently asked questions about HTML Essential Training.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
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.