Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Centering a table on a page using an external CSS

Status
Not open for further replies.

dad13

Programmer
Feb 12, 2001
4
US
Does anyone know how to center a table on a page using an external CSS. I am trying to eliminate the Deprecated <CENTER> tag from my html code.

the current html code is :
<HEAD>
<TITLE </TITLE>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;generic.css&quot; />
</HEAD>
<BODY>
<CENTER>
<TABLE WIDTH=&quot;90%&quot; NAME=&quot;tblParent&quot; >
<TR><TD> something here</TD></TR>
</TABLE>
</CENTER>

my external CSS contains:
table
{
padding: 0.0cm;
background-color: #EBE6DE
}
 
You could add this to the table's style:

position: relative;
left: 50%;

I'm not sure if that's the best way to do it or not though...
 
Have you tried <div align=&quot;center&quot;>?

I don't think that one is deprecated.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
is the center attribute deprecated for the <table> tag?

ie. <table align=center> ??
 
I looked it up on the internet, the 'align=' attribute for the 'TABLE' and 'DIV' tags is deprecated.
 
If they're deprecated, it must be in favor of some other way of centering. Any idea what it IS?
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
The style attrib float. Its a bit like the opposite of align. Dean Owen
 
Half answers are really no answer at all. If you're going to take the trouble to submit a response, PLEASE take the trouble to give a complete answer! Saying something is deprecated without offering an alternative is not particularly useful. Likewise, telling what the alternative IS, without giving a usage example isn't particularly helpful either.

According to the &quot;Index of the HTMLL 4.0 Elements&quot; centering is accomplished with the {text-align:center} style sheet attribute, but it isn't apparent whether this works on tables or not.

According to the same source, the only options for the float attribute are left or right, and it's main purpose is to allow text to flow around images. It's not obvious how it will work on tables either. Some browsers may allow a center option for float, but I wouldn't count on it.

What it boils down to is we still don't have a definitive answer yet. I've got some time this afternoon, I'll experiment.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
This works to center a table in NN 4.7 and IE 5.5:
Code:
<div style=&quot;text-align:center&quot;>
<table width=&quot;50%&quot; border=&quot;2&quot;>
   <tr>
      <td>this is the table</td>
   </tr>
</table>
</div>
If you want the text centered with the cell:
Code:
<td><span style=&quot;text-align:center&quot;>this is the table</span></td>
Putting that style on the table or the table cell does NOT work in NN 4.7 (it does in IE 5.5), but using the span tag works in both.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thank you very much, I will try your suggestions.
This is the first time I am using CSS.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top