Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

How to CENTER <td> within <tr>?

Nov 18, 2010 12:58PM PST

Greetings,

I wrote a pgm to build a HomePage of DropDownMenu Links.
But I can't yet get the CENTERing html right.
The code below is for two DropDowns per <tr>.
But usually it is more DropDowns per <tr>, and many ROWs.
So, How can I CENTER <td>s within <tr>?
Thanks...vmars316 (win7 home premium)

<table width="100%" border="0" align="center" cellspacing="0" cellpadding="0">
<tr><td width="200" height="28">
<!-- <form name="Best_COLOR_Sites"> --> <!-- rgb(250,240,255) -->
<select style="width:200px; font:14px Arial Black; color:rgb(0,0,0); background-color:rgb(231,169,126);" name="menu" onchange="location=this.options[this.selectedIndex].value;">
<option selected="selected" value="">Best_COLOR_Sites</option>
<option value="http://kuler.adobe.com/">Adobe colors schemes themes</option>
<option value="http://colorschemedesigner.com/">Best Color Tool Schemes</option>
</select>
</td><td width="200" height="28">
<!-- <form name="Bible_related"> --> <!-- rgb(250,240,255) -->
<select style="width:200px; font:14px Arial Black; color:rgb(0,0,0); background-color:rgb(231,169,126);" name="menu" onchange="location=this.options[this.selectedIndex].value;">
<option selected="selected" value="">Bible_related</option>
<option value="http://www.biblegateway.com/versions/">50 Bible VERSIONS</option>
<option value="http://www.biblesforamerica.org/CommentsAndQuestions.aspx">BFA Comments & Questions</option>
</select></td></tr></table>

Discussion is locked

- Collapse -
Center the TD or
Nov 19, 2010 6:33AM PST

center the contents within the TD?

To center the contents, just apply a style to the TD element that says "text-align: center". The TD expands to the width of the TR, so the TD can't be centered unless you set it to a fixed width.

~Sovereign

- Collapse -
I want to center multiple TDs within TR
Nov 20, 2010 2:56AM PST

I don't want to center within TD,
I want to center multiple TDs within TR.
Thanks...

- Collapse -
A tr is as wide as the sum of its tds
Nov 20, 2010 5:04AM PST

what's there to center?

Btw - tables are meant to display tabular data, not to be misused for layout.

- Collapse -
think of WordPad
Nov 20, 2010 6:03AM PST

"what's there to center?"
Quite a silly answer, and not at all helpful.

Now think of WordPad
and suppose that you don't assign sentences an alignment.
And suppose you only have two words in each sentence.
All sentences then start at the left side of document.

Now SelectAll, and click on Alignment CENTER.
All sentences now start in the center of page, and move outward left and right equally.

That's the kind of CENTERing I am after.
Thanks...vmars

- Collapse -
Re: centering
Nov 20, 2010 6:19AM PST

I did it differently. No tr, no td. But it centers perfectly.

<html><body>
<p style='text-align:center'>Short sentence</p>
<p style='text-align:center'>This is a longer sentence</p>
</body></html>

- Collapse -
<table width="100%" border="0" style="text-align:center"
Nov 23, 2010 12:17AM PST
- Collapse -
This Works quite well!
Nov 23, 2010 12:23AM PST
- Collapse -
Apparently, you don't understand tables
Nov 20, 2010 7:52PM PST

<table>
<tr>
<td>whatever</td>
<td>whatever</td>
<td>whatever</td>
</tr>
</table>

TR will be as wide as the sum of the TDs. (As I already said)

That is totally different from centering something on a page - or are you really asking how to center your TABLE???

- Collapse -
Look at it this way
Nov 20, 2010 5:18AM PST

Draw a table on a sheet of paper with one row and two columns.

How do you position the columns? There is only one way, the 'table' is fixed already when you drew the outline. The only way columns can be placed is next to each other, with fixed widths.

If you want a space between the table border and the columns then you have to cheat and add empty column's, and inside those use nbsp:'s to add width, or even an image that blends with the background, but that only works if the background is a single color.

I notice your cellspacing and cellpadding are set to 0. Have you tried other settings?

Mark

- Collapse -
Sorry, there was a problem submitting your post. Please try
Nov 23, 2010 12:12AM PST

Sorry, there was a problem submitting your post. Please try again.

Pls, how come?

- Collapse -
It happens occasionally.
Nov 23, 2010 4:46AM PST

Please re-post.

Mark

- Collapse -
And by the way
Nov 23, 2010 6:19AM PST

I asked whether you are looking to center the contents within a TD and you said no, but it was indeed what you were looking for.

~Sovereign

- Collapse -
<tr style="text-align:center">
Nov 23, 2010 12:11PM PST

"center the contents within a TD"
Sorry, but I still think I am concerned with
centering within a <tr>

Like what "Crailsheim7180" Posted", PLUS what " Kees_B" Posted:
<table>
<tr style="text-align:center">
<td>whatever</td>
<td>whatever</td>
<td>whatever</td>
</tr>
</table>

Sovereign: "I asked whether you are looking to center the contents within a TD and you said no, but it was indeed what you were looking for."
Sovereign, if you still feel the same way; Could you code what yours would look like? Cause I don't see what you mean yet.

Thanks...vmars

btw: I still cannot Post as vmars316
can one of you Moderator fix it?
Thanks

- Collapse -
Strange
Nov 23, 2010 8:46PM PST

You seem to have two CNET accounts and have been posting with each;

vmars956 - http://www.cnet.com/profile/vmars956/ with 163 forum posts, and
cmars316 - http://www.cnet.com/profile/vmars316/ with 35 forum posts.

What error message do you see when you attempt to post as vmars316? Does this happen when you Preview a post as well, or just when you hit Submit?

See if you can post in the Test Forum.

Mark

- Collapse -
just when I submit
Nov 24, 2010 8:05AM PST

It happens just when I click on Submit.

- Collapse -
I don't know how else to explain it
Nov 24, 2010 9:57PM PST

A table is not necessarily as wide as your page - it is as wide as the sum of the columns inside of it. There is no centering columns inside a table. Draw a grid - there you go. But if your table is NOT as wide as your page, then centering that entire table is an option. The columns inside it are still lined up next to each other inside the outer table border, but the entire thing is now centered. In order to center stuff in a tr, there would have to be room to move it right, left, or center - you don't get that in a table.

A table IS NOT equal to a page and has nothing to do with centering text in Notepad or Word or whatever.

- Collapse -
Yor account was banned...
Nov 24, 2010 5:23AM PST

You posted unsolicited links to your website in a couple different forums in quick succession. That's considered advertising/spamming under the forum policies, so a spam ban was requested. Mods will often look at the member's profile to get a feel for the member's history before making the request, then give the member the benefit of the doubt, responding to the member with a note that unsolicited linking is generally not permitted. However, the profiles were down for well over a month and we've been hit hard with spammers as of late, so your previous posting history was likely not reviewed before the request was made.

That said, I don't believe you were intentionally attempting to spam your website, so I've taken care of it; You should now be able to post under your other account to keep track of all your posts under a single username. Just try to avoid unsolicited linking in the future.

Regards,
John

- Collapse -
Yes, I figured I was banned, just didn't know why.
Nov 24, 2010 8:33AM PST

John,
Yes, I figured I was banned, just didn't know why.
The Post showing ddMenu_1.html, ddMenu_2.html, ddMenu_3.html
were Examples to demonstrate the point I was trying to communicate.

Btw John: I have written a (windows)FREEWARE program, that creates
an html page of Internet_Favorite. I use this ddMenu.html page
as my HomePage. Actually, I have two Utility freeware pgms,
one Builds an html page, as above.
The other is a DeskTop Sort program, hbSort.
And I would like to Post them at cnet somewhere.
Can I Post them at PC_utilities_Forum &/or Webware_Forum.
Thanks...vmars316

- Collapse -
Try Upload.com
Nov 24, 2010 7:32PM PST
https://upload.cnet.com/

Sorry but Forum Policy does not allow members to promote their own software i these forums.

Mark