align a image in xhtml ( center ? )

M

Mark Strain

can any one tell me how to align an image to the centre of the page using
xhtml. i've tryed

<p><img src="my pic" align="middle"/></p>

the pic still is displayed on the left and not in the centre -
im told you cant use the center tag in xhtml
 
M

Matti Kiviharju

Mark said:
can any one tell me how to align an image to the centre of the page using
xhtml. i've tryed

<p><img src="my pic" align="middle"/></p>

the pic still is displayed on the left and not in the centre -
im told you cant use the center tag in xhtml

Hmm.. <div align="center"><img src="your pic"></div> I don't know other
ways. Align in picture is for text around picture.
 
R

Richard

can any one tell me how to align an image to the centre of the page
using
xhtml. i've tryed
<p><img src="my pic" align="middle"/></p>
the pic still is displayed on the left and not in the centre -
im told you cant use the center tag in xhtml

<p style="text-align:center">
<p style="margin:nn%>
where nn is an appropriate number.

align="middle" is purely for tables.
 
S

Steve Pugh

Which shouldn't work in HTML or XHTML (see below). But some browsers
may guess what you mean, some of the time.

You can in XHTML 1.0 Transitional.
You can't in XHTML 1.0 Strict or XHTML 1.1 (nor in HTML 4/4.01
Strict).

CSS is the way to go, the exact code would depend on what you content
really is but the first of the three examples given by RtS will, most
surprisingly, work in many cases.
<p style="text-align:center">

Wow. That's actually correct syntax and will centre the image. But,
and this is a question for the OP, is a single image really a
paragraph?
<p style="margin:nn%>
where nn is an appropriate number.

Only if the image itself has a % width. Because margin: 30%; with a
200px wide image will only be centred if the window is exactly 500px
wide. Also margin: 0 30%; would make more sense
align="middle" is purely for tables.

No it's not. The only elements for which align="middle" is valid are
APPLET, IFRAME, IMG, INPUT and OBJECT where it aligns the element to
the vertical middle of the line which contains it.

The align attribute of tables can take the values left, center or
right. Perhaps you're confused with the valign attribute of certain
table child elements?

Steve
 
S

Sid Ismail

On Tue, 25 Jan 2005 19:24:44 GMT, Matti Kiviharju

: Align in picture is for text around picture.

That's changed - use CSS.

Sid
 
S

Sid Ismail

: The align attribute of tables can take the values left, center or
: right. Perhaps you're confused with the valign attribute of certain
: table child elements?

ALIGN=top|middle|bottom|left|right (image alignment)
from: http://www.htmlhelp.com/reference/html40/special/img.html

I use middle often when e.g. there are 3 images horizontally for instance
and you want to align them in the "middle" not on the baseline and thus
avoiding a skyscraper effect.

Sid
 
S

Steve Pugh

Sid Ismail said:
: The align attribute of tables can take the values left, center or
: right. Perhaps you're confused with the valign attribute of certain
: table child elements?

ALIGN=top|middle|bottom|left|right (image alignment)
from: http://www.htmlhelp.com/reference/html40/special/img.html

Yes? You're just repeating a part of my post that you snipped.
"The only elements for which align="middle" is valid are
APPLET, IFRAME, IMG, INPUT and OBJECT where it aligns the element to
the vertical middle of the line which contains it."

Steve
 
S

Sid Ismail

: >
: >: The align attribute of tables can take the values left, center or
: >: right. Perhaps you're confused with the valign attribute of certain
: >: table child elements?
: >
: >ALIGN=top|middle|bottom|left|right (image alignment)
: >from: http://www.htmlhelp.com/reference/html40/special/img.html
:
: Yes? You're just repeating a part of my post that you snipped.
: "The only elements for which align="middle" is valid are
: APPLET, IFRAME, IMG, INPUT and OBJECT where it aligns the element to
: the vertical middle of the line which contains it."


The OP said:
<p><img src="my pic" align="middle"/></p>

I was saying that middle is a valid attribute for image.

Your previous post confirmed it and said that middle is not valid for
_Tables_. Humble apologies.

Sid
 
Joined
Jan 10, 2009
Messages
1
Reaction score
0
CSS Float

Use float:left in your CSS to replace align="left" in an img tag for XHTML 1.0 Strict validity.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top