Sams Teach Yourself HTML 4 in 24 Hours

Sams Teach Yourself HTML 4 in 24 Hours

By Dick Oliver

Horizontal Image Alignment

As discussed in Hour 5, "Text Alignment and Lists," you can use <div align="center">, <div align="right"> , and <div align="left"> to align part of a page to the center, right margin, or left margin. These tags affect both text and images.

For example, the last <img /> tag in Figure 10.1 occurs between the <div align= "center"> tag and the closing </div> tag. You can see in Figure 10.2 that this causes the image (as well as the text below it) to be centered on the page. Like text, images are normally lined up with the left margin unless a <div align="center"> or <div align="right"> tag indicates that they should be centered or right-justified.

As the first three images in Figures 10.4 and 10.5 demonstrate, you can also use <div align="center"> to center more than one image at a time. Since there are no <br /> or <p> tags between them, the three images all appear on one line and the entire line is centered horizontally in the browser window.

10fig04.gif

Figure 10.4 This page contains examples of both horizontal and vertical image alignment, as well as automatic wrapping of text around images.

10fig05.jpg

Figure 10.5 The HTML page listed in Figure 10.4, as it appears in a Web browser.

You can also make text wrap around images, as the paragraph around the pictures of Mars and Venus in the lower-middle part of Figure 10.5 does. You do this by including an align attribute within the <img /> tag itself, as shown in the fifth and sixth <img /> tags in Figure 10.4.

<img align="left" /> aligns the image to the left and causes text to wrap around the right side of it. As you'd expect, <img align="right" /> aligns the image to the right and causes text to wrap around the left side of it.

You can't use <img align="center" /> because text won't wrap around a centered image. You must use <div align="center"> if you want an image to be centered on the page, as I did with the top image in Figures 10.4 and 10.5.

Share ThisShare This

Informit Network