Centering an Image

windows

Guest
I have a picture that I need to center on the page, but when i put align="center" into <img src> tag it doesn't work even though if i put align="right" it works. What can I do about it?<br />
<br />
Thanks in advance,<br />
Lani<!--content-->Align on an image refers to alignment with the surrounding text.<br />
<br />
You have to center from a P or div like this:<br />
<br />
<p style="text-align:center"><br />
<img etc...<br />
</p><!--content-->or simplest solution is using the <center> tags<br />
<br />
<center><br />
<img src...><br />
</center><br />
<br />
or you could put the image in a table.<br />
<br />
<table align="center" border="0"><br />
<tr><td><br />
<img src...><br />
</td></tr></table><!--content-->Stay away from the <center> element.<br />
<br />
The <center> element was invented by Netscape before they added support for the HTML3 <div> element.<br />
The <center> element is deprecated in HTML4 and XHTML. <br />
The recommendation is to use <div align="center"> instead of <center>.<br />
<br />
<!-- m --><a class="postlink" href="http://www.w3.org/TR/REC-html40/present/graphics.html#edef-CENTER">http://www.w3.org/TR/REC-html40/present ... def-CENTER</a><!-- m --><!--content-->Actually both <center> and the align attribute are depreciated.<br />
<br />
It is a good idea to use CSS attributes for forward compatibility. I think they both throw a warning message if you put them through an HTML4 validator.<!--content-->thanks guys, but I have never had any problems with the <center> tag in any validator. but I will keep that in mind.<!--content-->It's interesting that a number of tags that are deprecated will still validate for <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"<br />
"http://www.w3.org/TR/html4/loose.dtd"> <br />
<br />
<p align="center"> together with <body bgcolor="whatever"> and <body background="whatever.gif"> still validate. I'm sure there are a few others as well. <br />
<br />
Maybe it's to do with the "loose" in the DTD.<br />
<br />
Neil<!--content-->Originally posted by Option1 <br />
Maybe it's to do with the "loose" in the DTD.<br />
<br />
Yes. The loose specification allows older tags to be used for formatting purposes. Basically, it gives you the power of both old and new. It's my preference of DTD.<br />
<br />
"strict" would most likely cancel out any deprecated tags.<!--content-->Originally posted by COBOLdinosaur <br />
Actually both <center> and the align attribute are depreciated.<br />
<br />
It is a good idea to use CSS attributes for forward compatibility. I think they both throw a warning message if you put them through an HTML4 validator. <br />
<br />
Do HTML tags really depreciate? Man am I in trouble if they do :)<!--content-->Originally posted by Lani <br />
I have a picture that I need to center on the page, but when i put align="center" into <img src> tag it doesn't work even though if i put align="right" it works. What can I do about it?<br />
<br />
Thanks in advance,<br />
Lani <br />
To expand on what CobolDino said:<br />
<br />
there are several align attributes associated with the image tag. <br />
<br />
align=left and align=right are floating alignments. They will place an image as far left or as far right on the page as any other elements/code allow for. The three standard alingment attributes:<br />
<br />
align=top/bottom/middle <br />
<br />
align images to corresponding text. <br />
<br />
Kevin<!--content-->They are definitely deprecated, although they are allowed in Transitional (I think). I'm going through that now.<!--content-->Interestingly, I had a page that used:<br />
<br />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" <br />
"http://www.w3.org/TR/html4/loose.dtd"> <br />
<br />
that wouldn't even work in NS 6.0 (I don't know if it works in 6.1 or not and I can't remember if the page validated or not, I seem to think it did).<br />
<br />
Yet simply by changing the DTD to:<br />
<br />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"<br />
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"><br />
<br />
it worked just fine.<br />
<br />
Strange that. Any explanations on why (that load of unmitigated crap) NS 6.0 wouldn't accept the original DTD?<br />
<br />
Anyway, to be sure now I use the second DTD.<br />
<br />
Neil<!--content-->The problem with depreciated tags is that they will be made <br />
obsolete at some point. The standard does not require support for them, and they will get dropped at some point. The argument for version backward compatibilty has been thrown away. The latest versions of both IE and Netscrap have serious backward compatibility problems, caused by moving closer to the standards.<br />
<br />
Code written for IE4 still works pretty well in IE 6, but probably won't in IE7. Netscrap 4 was absolutely deadended by Netscrap 6. There is zero support for the old DOM.<br />
<br />
I prefer to work to the loose.dtd because I need the flexibility, but I validate with strict.dtd and comment anything that has a potential for problems, because it will get a lot tougher when we have to support browsers that are XHTML compliant.<!--content-->I spent a good part of this afternoon at, um, work reading the material here and upgrading my current project to XHTML 1.0 Strict (just for fun), and found out alot:<br />
<br />
<!-- m --><a class="postlink" href="http://www.w3schools.com/xhtml/xhtml_reference.asp">http://www.w3schools.com/xhtml/xhtml_reference.asp</a><!-- m --><br />
<br />
Lots of interesting stuff to keep in mind when doing your next project like "attribute 'target' is no longer allowed in an anchor reference". I'll have to find a different way of doing it. I've only been doing this for 3-4 months, so I'm not very good at javascript yet. Does anybody know a generic (ie. simple) way of linking to a blank browser? <br />
<br />
It's good to see some interest in standards here! Almost enough for another forum, eh? (Nudge, nudge, wink, wink, say no more, say no more???)<!--content--><a href=http://www.htmlforums.com/archive/index.php/"http://www.javascript-fx.com" onclick="window.open(this.href);return false;">open</a><!--content-->Originally posted by kevin <br />
Do HTML tags really depreciate? Man am I in trouble if they do :) <br />
<br />
Actually, the term is deprecate (without the i). Very similar spelled words as well as meanings. The two words are often interchanged.<br />
<br />
I figure I would through this in for anyones's FYI ~~<br />
<br />
From the W3C site :<br />
A deprecated element or attribute is ont that has been outdated by newer constructs (HTML versions). Deprecated elements may become obsolete (unusable) in future versions of HTML.<br />
User agents (browser companies) should continue to support deprecated elements for reasons of backward compatibility.<br />
Authors should use style sheets to achieve stylistic and formatting effects rather than HTML presentational attributes.<br />
<br />
Deprecate :<br />
1. To deplore.<br />
2. To express condemnation of something or somebody.<br />
3. To seek to avert.<br />
4. To pray against.<br />
5. To express disapproval of.<br />
6. To make little of.<br />
7. To belittle.<br />
8. To seek deliverance from.<br />
9. To desire the removal of.<br />
10. To disapprove strongly.<br />
<br />
From Encarta :<br />
To "deprecate" something is to deplore or condemn it as wrong in itself.<br />
To "depreciate" something is to belittle or disparage it, although it may not be wrong or bad in itself.<br />
Both words have common synonyms.<br />
<br />
I figure as long as you have the correct DOCTYPE specified and the next few versions of browsers will still accept backwards compatability, you don't have much to worry about. Do try to use style sheets though. They will give you much more control and abilities anyways.<!--content-->Originally posted by <htmlite> <br />
...<br />
<br />
I figure I would through this in for anyones's FYI ~~<br />
<br />
... I think you meant throw ;)<br />
Neil<!--content-->LMAO.<br />
Speling izn't mi bestest subjekt.<!--content-->
 
Back
Top