04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

using urls <strong>with</strong> images<br />

: it’s not just relative links anymore<br />

The src attribute can be used for more than just relative links; you can also put a URL<br />

in your src attribute. Images are stored on Web servers right alongside <strong>HTML</strong> pages, so<br />

every image on the Web has its own URL, just like Web pages do.<br />

You’ll generally want to use a URL for an image if you’re pointing to an image at a different<br />

Web site (remember, for links and images on the same site, it’s better to use relative paths).<br />

Here’s how you link to an image using a URL:<br />

<br />

Sharpen your pencil<br />

Here’s a “Sharpen your pencil” that is actually about pencils (oh, and images too). This exercise involves a bit of<br />

trivia: Given a typical, brand-new pencil, if you drew one continuous line <strong>with</strong> it, using the entire pencil up, how<br />

long would the line be?<br />

What’s that got to do <strong>with</strong> images? To find the answer you’re going to have to write some <strong>HTML</strong>. The answer to<br />

this trivia is contained in the image that is at the URL: http://www.headfirstlabs.com/trivia/pencil.gif. Your job is to<br />

add an image to this <strong>HTML</strong> and retrieve the answer:<br />

<br />

<br />

Sharpen your pencil trivia<br />

<br />

<br />

How long a line can you draw <strong>with</strong> the typical pencil?<br />

<br />

<br />

<br />

<br />

174 Chapter 5<br />

To include an image using its URL,<br />

just put the whole URL of the<br />

image in the src attribute.<br />

Put your image element here.<br />

The URL is the path to the image,<br />

so the filename at the end is always<br />

the filename of an image. There’s<br />

no such thing as a default image<br />

like there is for Web pages.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!