Aligning an Image on Your Web Page
By Stephen Bucaro
You place an image on a webpage using the <img src="imagename" /> tag.
An img tag creates an inline box. This means the the browser renders the image
along with any other inline elements (like text) from left to right, top to bottom.
This is some text. This is some text. This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text. This is some text. This is some text.
By default the baseline of the image is placed on the same baseline as the text.
However you can set the align attribute to "bottom", "middle" or "top" to
change where the baseline of the image will be located relative to the baseline of the text.
align attribute:
align="bottom" - default
align="top"
align="middle"
align="left"
align="right"
This is some text. This is some text. This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
<img align="middle" src="cherry.jpg" />
This is some text. This is some text. This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text. This is some text. This is some text.
<img align="top" src="cherry.jpg" />
As you can see from the examples above, if you set the align attribute to
"middle" or "top", it causes some space between the lines of text. If this is undesirable,
you might use some other layout elements, such as placing the image and the text inside table cells.
This is some text. This is some text. This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text. This is some text. This is some text.
<img align="left" src="cherry.jpg" />
This is some text. This is some text. This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text. This is some text.This is some text.
<img align="right" src="cherry.jpg" />
As you can see in the examples above, if you set the align attribute to
"left" or "right", it causes text to wrap next to the image. This can cause a problem
when text that you don't want to wrap continues to wrap. To stop the text from wrapping,
use a break tag (<br>) with its clear attribute set to the same
value as the <img> tags align attribute. An example is shown below.
<br clear="left" />
Or you can use <br clear="all" /> to clear any previous align setting.
|