metalquake
07-01-2004, 12:40 AM
Does anyone know the html code to put an image right in the center of a webpage? You know, vertically and horizontally centered, on all resoulutions. Thanks.
![]() | View Full Version : Centering images in a webpage? metalquake 07-01-2004, 12:40 AM Does anyone know the html code to put an image right in the center of a webpage? You know, vertically and horizontally centered, on all resoulutions. Thanks. DWS 07-01-2004, 12:53 AM Create a table, and set the table properties so content within the table is centered horizontally and vertically. Something like: <table align="center" border="0"> <tr> <td align="center" valign="middle"><img src="http://www.yoursite.com/image.gif"></td> </tr> </table> HTH the_pm 07-01-2004, 12:58 AM That won't entirely do it, since the table is not stretched to fit the entire screen. It would center horizontally, but not vertically (if this was all that was necessary a simple <div> would suffice). Try adding style="height:100% ; width:100%" into the table tag and you should get the desired result. It would also be perfectly appropriate to move this into a style sheet. metalquake 07-01-2004, 01:00 AM OK thanks that really helped! :) ktwilight 07-01-2004, 06:44 PM i would have thought the table tag doesn't understand or read the height attribute. or is it because it's css instead of xhtml? the_pm 07-01-2004, 07:30 PM It should read it just fine, though I think in IE you have to set both the width and height in CSS for it to read the height property (could be wrong). That's fine since you need to specify both anyway. I've never run into any problems with this though, unless you've got anything outside of the table pushing it down. For true cross-browser support, you need to specify: html, body { height:100% ; width:100% } as well. ktwilight 07-02-2004, 05:46 PM aha~ first time i heard of this really. thanks for the info. :) |