Floating Images
Topics on This Page
Floating Images
The clear Attribute of <br>
Floating Images in Headings
Example
Foating Images
When you use any of the align values other than left or right,
the image is displayed much as if it's just a letter of the alphabet. It stays right next
to any text that you code beside it: you can position the image vertically with respect
to the text, but you can only have one line of text beside it.
align="left" and align="right" turn the image into a floating
image. The image is moved to the far left or right, and text flows around it.
Until Netscape 6, all browsers automatically applied several pixels of horizontal space
(hspace) to a floating image when hspace is omitted. Netscape 6
has seen fit to do away with this, and if you don't specify hspace the text
butts right up against the image when viewed in Netscape 6. Unfortunately, this is true in both
standards and quirks mode it would have made a lot more sense to me to keep
the default hspace in quirks mode.
Here are some examples.
I've placed these examples inside
tables so that I don't need to include as much text to illustrate floating images, but the
same applies to images that are not inside tables.
|
The image in this example has align="left" and hspace="5". As you
can see, there's a nice gap between the text and the image. The text aligns with the
top of the image and flows around it. Floating images that don't specify hspace
look much like this in browsers other than Netscape 6.
|
|
The image in this example has align="left" and hspace="0". The text
runs right up against the image. This is the default layout for align="left"
in Netscape 6. Most of us have relied on the default hspace applied by other
browsers, so a lot of web pages will have floating images that look like this when
you look at older pages with Netscape 6.
|
|
This example shows align="right" and hspace="5". The text is
left-justified and flows around the image. Once the text reaches the bottom of the
image, it again extends to the right margin.
|
|
This example is just like the one before it, except that the image and text are inside
a <p> tag that specifies align="right". The text snuggles up against the
image with jagged edges on the left rather than the right.
|
|
The image doesn't have to be the first thing inside the paragraph. Here, I've put
the image right after this sentence.
The image moves down to the far left of the next line, and the paragraph continues on the
same line and then flows around the image. Once the
text reaches the bottom of the image, it again extends to the left margin.
|
|
This is much like the previous example except that the image includes vspace="10"
and hspace="10" to move the text a little further away from the image.
vspace and hspace essentially add to the size of the image, and you can often
improve the looks of your pages by choosing good values for them.
|
|
You can have both a left-aligned image and a right-aligned image. Here I've placed both <img>
tags before any of the text in the paragraph, and I've made the right-aligned one shorter than
the left-aligned one.
|
|
Here I've place the <img> tag for the left-aligned
image before any of the text, but I've moved the other <img> tag down after some of the text.
Floating images provide a lot of flexibility.
|
The clear Attribute of <br>
The <br> tag includes an attribute clear="left|right|all" that you can use
to move text down below a floating image.
Floating Images in Headings
You can include floating images inside an <h?> tag. Here are some examples where I've
placed floating images inside an <h2> tag that includes align="center".
My Heading
The <h2> tag has align="center" and the <img> tag that's included
inside the heading has align="left". Notice that the paragraph that follows
the <h2> tag floats around the image. Also notice that the heading is centered
within the space remaining beside the image rather than being centered in
the browser window.
|
My Heading
Here I've added a <br> tag before "My Heading" inside the <h2> tag,
and I've also added <br clear="all"> after "My Heading".
|
My Heading
Here I've got both a left-aligned image and a right-aligned image inside the <h2>
tag. The heading is now centered in the table.
|
My Heading
Here I've substituted a transparent image for the right-aligned one. This is a technique
you can use to center the heading.
|
Example
Try playing with floating images and with the clear attribute
of <br>. Try various image sizes. If you want to use some real
images, you can use these:
| Name | Width | Height |
| images/bez5a.jpg | 270 | 269 |
| images/bird02.jpg | 320 | 240 |
| images/dan3.jpg | 248 | 323 |
| images/Flower01.gif | 200 | 200 |
| images/Larry54.jpg | 268 | 197 |
| images/browndot.gif | 1 | 1 |
images/transdot.gif (transparent) | 1 | 1 |
Try out various things with the transparent image (transdot.gif).