Centering text - why doesn't this work?

liunx

Guest
Hi all. I'm frustrated, because the simplest chuck of code I've written in years won't work. Any idea why? Here's the page in its entirety:<br />
<br />
<html><br />
<body topmargin="0" leftmargin="0"><br />
<table cellspacing=0 cellpadding=0 border=0 style="table-layout:fixed" width=800 align=center><br />
<p align="center">Info For Members</p><br />
</table><br />
</body><br />
<html><br />
<br />
I need the style setting in the table tag for future code on the page, as well as the centered 800px table, but for some reason the "Info For Members" line is not centered (it is left-justified). However, if I do THIS:<br />
<br />
<html><br />
<body topmargin="0" leftmargin="0"><br />
<table cellspacing=0 cellpadding=0 border=0 style="table-layout:fixed" width=800 align=center><br />
<p align="center">Info For Members</p><br />
<p align="center">Line 2</p><br />
</table><br />
</body><br />
<html><br />
<br />
Then "Info For Members" is still not centered, but the new line "Line 2" is centered.<br />
<br />
I'm stumped, hopefully I'm just missing something really really obvious and one of you will catch it. Thanks for your help!<br />
<br />
TBor<!--content-->Firstly I'd suggest you use a full doctype etc. This is so real browsers will know how to interpret what you tell them.<br />
Secondly, as I just wrote in your other thread, you need to use css for layout.<br />
Thirdly, this is the code that should actually do what you want:<br />
<br />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"<br />
"http://www.w3.org/TR/html4/loose.dtd"><br />
<html><br />
<head><br />
<title>Untitled</title><br />
<style type="text/css"><br />
<!--<br />
body {<br />
text-align: center;<br />
}<br />
#main {<br />
margin: auto;<br />
text-align: left;<br />
width: 800px;<br />
}<br />
.center {<br />
text-align: center;<br />
}<br />
--><br />
</style><br />
</head><br />
<body><br />
<div id="main"><br />
<p class="center">Info For Members</p><br />
<p class="center">Line 2</p><br />
</div><br />
</body><br />
</html><!--content-->Thanks Dave! That seems to work for me.<br />
<br />
Out of curiousity, why didn't my original code work?<br />
<br />
TBor<!--content-->Well a table should contain rows and columns, rather than straight paragraphs.... The paras would need to be in a table cell.<br />
<br />
e.g. (reusing the code of your original sample)<br />
<html><br />
<body topmargin="0" leftmargin="0"><br />
<table cellspacing=0 cellpadding=0 border=0 style="table-layout:fixed" width=800 align=center><br />
<tr><br />
<td><br />
<p align="center">Info For Members</p><br />
<p align="center">Line 2</p><br />
</td><br />
</tr><br />
</table><br />
</body><br />
<html><!--content-->
 
Back
Top