Web Hosting, Design, & Coding

General discussion

How to CENTER <td> within <tr>?

by vmars316 / November 18, 2010 12:58 PM 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>

Post a reply
Discussion is locked
You are posting a reply to: How to CENTER <td> within <tr>?
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: How to CENTER <td> within <tr>?
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Collapse -
Center the TD or
by Sovereign Forum moderator / November 19, 2010 6:33 AM 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
by vmars316 / November 20, 2010 2:56 AM PST
In reply to: Center the TD or

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
by Crailsheim7180 / November 20, 2010 5:04 AM PST

what's there to center?

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

Collapse -
think of WordPad
by vmars316 / November 20, 2010 6:03 AM 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
by Kees_B Forum moderator / November 20, 2010 6:19 AM PST
In reply to: think of WordPad

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"
by vmars956 / November 23, 2010 12:17 AM PST
In reply to: Re: centering
Collapse -
This Works quite well!
by vmars956 / November 23, 2010 12:23 AM PST
In reply to: Re: centering
Collapse -
Apparently, you don't understand tables
by Crailsheim7180 / November 20, 2010 7:52 PM PST
In reply to: think of WordPad

<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
by MarkFlax Forum moderator / November 20, 2010 5:18 AM 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
by vmars956 / November 23, 2010 12:12 AM PST
In reply to: Center the TD or

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

Pls, how come?

Collapse -
It happens occasionally.
by MarkFlax Forum moderator / November 23, 2010 4:46 AM PST

Please re-post.

Mark

Collapse -
And by the way
by Sovereign Forum moderator / November 23, 2010 6:19 AM 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">
by vmars956 / November 23, 2010 12:11 PM PST
In reply to: And by the way

"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
by MarkFlax Forum moderator / November 23, 2010 8:46 PM 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
by vmars316 / November 24, 2010 8:05 AM PST
In reply to: Strange

It happens just when I click on Submit.

Collapse -
I don't know how else to explain it
by Crailsheim7180 / November 24, 2010 9:57 PM 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...
by John.Wilkinson / November 24, 2010 5:23 AM 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.
by vmars316 / November 24, 2010 8:33 AM 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
by MarkFlax Forum moderator / November 24, 2010 7:32 PM PST
Popular Forums
icon
Computer Help 47,885 discussions
icon
Computer Newbies 10,322 discussions
icon
iPhones, iPods, & iPads 3,188 discussions
icon
Security 30,333 discussions
icon
TVs & Home Theaters 20,177 discussions
icon
HDTV Picture Setting 1,932 discussions
icon
Phones 15,713 discussions
icon
Windows 7 6,210 discussions
icon
Networking & Wireless 14,510 discussions

Tech Tip

Know how to save a wet phone?

It's not with a dryer and it's not with rice. CNET shows you the secret to saving your phone.