tags:

views:

51

answers:

4
<img ...>
<p>..</p>

Without setting align="left" on img,p will start from a blank line.

<img ... align="left">
<p>..</p>

But after setting align="left",p will come up around img,why?

+2  A: 

I guess that <img> align attribut will work like CSS float property. It makes your image float. If you want <p> to stay under <img> so you should do it like this.

<img ... align="left" />
<div style="clear: both;"></div>
<p>..</p>

Float image to left or right using CSS

HTML uses the align attribute:

<img src="image.jpg" align="right">

XHTML uses an inline style:

<img src="image.jpg" style="float: right" /> 

The proof: HTML img align Attribute

The align attribute of <img> is deprecated, and is not supported in HTML 4.01 Strict / XHTML 1.0 Strict DTD.

Use CSS instead.

CSS syntax: <img style="float:right" />

Balon
Can you prove your guess?I don't think `align="left"` is the same as `float:left`
@OP: For all intents and purposes, yes, setting an image to `align="left"` (or right) is exactly the same as setting the `float` CSS property of that image. Balon's guess is correct.
Duroth
I've edited my answer and added a link to an article about this ;)
Balon
Is `image` the only special case?Is there any reason for this,or is it just a bug?
Okay, I've added the proof to my answer. It isn't a bug. It's just not suported in HTML 4.01 Strict / XHTML 1.0 Strict DTD and you should use CSS float property instead.
Balon
@unknown: That's how floats work. Anything following the float wraps around it. It's easier to see with images because they have inherent width.
Anonymous
The align attribute is html predates css. It isn't a bug. The css float property was dfesigned as a generalization of this pre-css ability to "float" images.
Laurence Gonsalves
No,you can't simply replace `align` with `float` for `td`
Yes, because you have to replace `align` with `text-align` for `td`. Anyway `align` for `td` isn't deprecated.
Balon
So you need to edit your answer,because you are talking about it as if `align` can be replaced with `float` anywhere:)
Corrected :) My bad.
Balon
The only thing left to solve is:is image the only special case?
No, I think you can `align` all block elements. http://www.w3.org/TR/REC-html40/present/graphics.html#h-15.1.2
Balon
+1  A: 

Setting align html attribute to left or right on an image is equivalent to css floating the image.

Laurence Gonsalves
Is `image` the only special case?
No. IMG, OBJECT, and APPLET all behave this way. EMBED probably does too (though it's non-standard, so the spec doesn't mention it) See http://www.w3.org/TR/html4/struct/objects.html#h-13.7.4 in particular the bit where it says "This attribute specifies the position of an IMG, OBJECT, or APPLET with respect to its context." and later "Two other values, left and right, cause the image to float to the current left or right margin. They are discussed in the section on floating objects."
Laurence Gonsalves
A: 

Read about inline and block elements. I don't remember any good site (in English) with explanation of difference between these two types right now, so try to Google it.

Setting align="left" (this should be converted to its equivalent in CSS: float: left) makes img element floating. Once again read about floats.

Crozin
A: 

Perhaps it's better to try :

<p><img align="left" /></p>

Or may be :

<img align="left" />
<p style="clear:left"></p>
Leprosy