PC Review


Reply
Thread Tools Rate Thread

How to center a table?

 
 
Bob Altman
Guest
Posts: n/a
 
      28th Aug 2008
Hi all,

This has got to be a dumb question, but... What is the CSS property that I
would use to center a table on the web page?

If I set the table's Align property in the VS 2008 property window it
inserts align="center" into the <table> tag, and I get a validation warning
that attribute 'align' is considered outdated. Ok, so I probably need to
use a CSS style to do the same thing. But I've dug through all of the
categories in the Modify Style dialog and I can't find anything that sets
alignment or position to "center".

TIA - Bob

 
Reply With Quote
 
 
 
 
Bob Altman
Guest
Posts: n/a
 
      28th Aug 2008
"Mark Rae [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "Bob Altman" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> This has got to be a dumb question, but... What is the CSS property that
>> I would use to center a table on the web page?

>
> style="margin-left:auto;margin-right:auto;"


Thanks Mark. That's seriously non-intuitive!

Bob


 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      29th Aug 2008
CSS works on a "box" model, where each element in your page represents a
"box" of space. Every box has a width, interior padding, and exterior
margins.

By setting the margin-left and margin-right CSS properties to "auto", you
are essentially telling the browser to automatically set the margin for you,
but because you did that on both the left and the right, the individual
margins split the difference and you get a left margin and a right margin
that use up whatever space is not being used by your table "box".

-Scott

"Bob Altman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Mark Rae [MVP]" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> "Bob Altman" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>
>>> This has got to be a dumb question, but... What is the CSS property that
>>> I would use to center a table on the web page?

>>
>> style="margin-left:auto;margin-right:auto;"

>
> Thanks Mark. That's seriously non-intuitive!
>
> Bob
>



 
Reply With Quote
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      29th Aug 2008
Hi Bob,

You can use the text-align css propety at the parent container element to
perform horizontal alignment setting:

http://www.webmasterworld.com/forum83/4748.htm

http://www.ehow.com/how_2284643_left...align-css.html

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
>From: "Bob Altman" <(E-Mail Removed)>
>Subject: How to center a table?
>Date: Thu, 28 Aug 2008 09:24:41 -0700


>
>Hi all,
>
>This has got to be a dumb question, but... What is the CSS property that I
>would use to center a table on the web page?
>
>If I set the table's Align property in the VS 2008 property window it
>inserts align="center" into the <table> tag, and I get a validation

warning
>that attribute 'align' is considered outdated. Ok, so I probably need to
>use a CSS style to do the same thing. But I've dug through all of the
>categories in the Modify Style dialog and I can't find anything that sets
>alignment or position to "center".
>
>TIA - Bob
>
>


 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      29th Aug 2008
Doesn't that property setting inherit into the cells of the table causing
cell data to also be centered (which may not be desired)?

-Scott

"Steven Cheng [MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Bob,
>
> You can use the text-align css propety at the parent container element to
> perform horizontal alignment setting:
>
> http://www.webmasterworld.com/forum83/4748.htm
>
> http://www.ehow.com/how_2284643_left...align-css.html
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> (E-Mail Removed).
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/en-us/subs...#notifications.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>
>
> --------------------
>>From: "Bob Altman" <(E-Mail Removed)>
>>Subject: How to center a table?
>>Date: Thu, 28 Aug 2008 09:24:41 -0700

>
>>
>>Hi all,
>>
>>This has got to be a dumb question, but... What is the CSS property that I
>>would use to center a table on the web page?
>>
>>If I set the table's Align property in the VS 2008 property window it
>>inserts align="center" into the <table> tag, and I get a validation

> warning
>>that attribute 'align' is considered outdated. Ok, so I probably need to
>>use a CSS style to do the same thing. But I've dug through all of the
>>categories in the Modify Style dialog and I can't find anything that sets
>>alignment or position to "center".
>>
>>TIA - Bob
>>
>>

>



 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      29th Aug 2008
Yes, as I suspected, this does not work. It will center the contents of the
table, but not the table itself.

The correct way is as I've described using margin-left:auto and
margin-right:auto.

-Scott


"Scott M." <s-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Doesn't that property setting inherit into the cells of the table causing
> cell data to also be centered (which may not be desired)?
>
> -Scott
>
> "Steven Cheng [MSFT]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi Bob,
>>
>> You can use the text-align css propety at the parent container element to
>> perform horizontal alignment setting:
>>
>> http://www.webmasterworld.com/forum83/4748.htm
>>
>> http://www.ehow.com/how_2284643_left...align-css.html
>>
>> Sincerely,
>>
>> Steven Cheng
>>
>> Microsoft MSDN Online Support Lead
>>
>>
>> Delighting our customers is our #1 priority. We welcome your comments and
>> suggestions about how we can improve the support we provide to you.
>> Please
>> feel free to let my manager know what you think of the level of service
>> provided. You can send feedback directly to my manager at:
>> (E-Mail Removed).
>>
>> ==================================================
>> Get notification to my posts through email? Please refer to
>> http://msdn.microsoft.com/en-us/subs...#notifications.
>> ==================================================
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>>
>>
>> --------------------
>>>From: "Bob Altman" <(E-Mail Removed)>
>>>Subject: How to center a table?
>>>Date: Thu, 28 Aug 2008 09:24:41 -0700

>>
>>>
>>>Hi all,
>>>
>>>This has got to be a dumb question, but... What is the CSS property that
>>>I
>>>would use to center a table on the web page?
>>>
>>>If I set the table's Align property in the VS 2008 property window it
>>>inserts align="center" into the <table> tag, and I get a validation

>> warning
>>>that attribute 'align' is considered outdated. Ok, so I probably need to
>>>use a CSS style to do the same thing. But I've dug through all of the
>>>categories in the Modify Style dialog and I can't find anything that sets
>>>alignment or position to "center".
>>>
>>>TIA - Bob
>>>
>>>

>>

>
>



 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      30th Aug 2008
Oops, I mean to say that it will center the table AND the contents of the
table, which may not be desired.


"Scott M." <s-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Yes, as I suspected, this does not work. It will center the contents of
> the table, but not the table itself.
>
> The correct way is as I've described using margin-left:auto and
> margin-right:auto.
>
> -Scott
>
>
> "Scott M." <s-(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Doesn't that property setting inherit into the cells of the table causing
>> cell data to also be centered (which may not be desired)?
>>
>> -Scott
>>
>> "Steven Cheng [MSFT]" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi Bob,
>>>
>>> You can use the text-align css propety at the parent container element
>>> to
>>> perform horizontal alignment setting:
>>>
>>> http://www.webmasterworld.com/forum83/4748.htm
>>>
>>> http://www.ehow.com/how_2284643_left...align-css.html
>>>
>>> Sincerely,
>>>
>>> Steven Cheng
>>>
>>> Microsoft MSDN Online Support Lead
>>>
>>>
>>> Delighting our customers is our #1 priority. We welcome your comments
>>> and
>>> suggestions about how we can improve the support we provide to you.
>>> Please
>>> feel free to let my manager know what you think of the level of service
>>> provided. You can send feedback directly to my manager at:
>>> (E-Mail Removed).
>>>
>>> ==================================================
>>> Get notification to my posts through email? Please refer to
>>> http://msdn.microsoft.com/en-us/subs...#notifications.
>>> ==================================================
>>> This posting is provided "AS IS" with no warranties, and confers no
>>> rights.
>>>
>>>
>>>
>>> --------------------
>>>>From: "Bob Altman" <(E-Mail Removed)>
>>>>Subject: How to center a table?
>>>>Date: Thu, 28 Aug 2008 09:24:41 -0700
>>>
>>>>
>>>>Hi all,
>>>>
>>>>This has got to be a dumb question, but... What is the CSS property that
>>>>I
>>>>would use to center a table on the web page?
>>>>
>>>>If I set the table's Align property in the VS 2008 property window it
>>>>inserts align="center" into the <table> tag, and I get a validation
>>> warning
>>>>that attribute 'align' is considered outdated. Ok, so I probably need
>>>>to
>>>>use a CSS style to do the same thing. But I've dug through all of the
>>>>categories in the Modify Style dialog and I can't find anything that
>>>>sets
>>>>alignment or position to "center".
>>>>
>>>>TIA - Bob
>>>>
>>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      1st Sep 2008
Thanks for your followup Scott,

Yes, I think your suggestion is reasonable. Using Margin will be preferred.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(E-Mail Removed).

--------------------
>From: "Scott M." <s-(E-Mail Removed)>
>Subject: Re: How to center a table?
>Date: Fri, 29 Aug 2008 19:30:04 -0400


>
>Oops, I mean to say that it will center the table AND the contents of the
>table, which may not be desired.
>
>
>"Scott M." <s-(E-Mail Removed)> wrote in message
>news:%(E-Mail Removed)...
>> Yes, as I suspected, this does not work. It will center the contents of
>> the table, but not the table itself.
>>
>> The correct way is as I've described using margin-left:auto and
>> margin-right:auto.
>>
>> -Scott
>>
>>
>> "Scott M." <s-(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Doesn't that property setting inherit into the cells of the table

causing
>>> cell data to also be centered (which may not be desired)?
>>>
>>> -Scott
>>>
>>> "Steven Cheng [MSFT]" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> Hi Bob,
>>>>
>>>> You can use the text-align css propety at the parent container element
>>>> to
>>>> perform horizontal alignment setting:
>>>>
>>>> http://www.webmasterworld.com/forum83/4748.htm
>>>>
>>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Center a table in asp.net 2.0? Scott M. Microsoft ASP .NET 7 3rd Apr 2007 07:26 PM
Vertical center a table =?Utf-8?B?QmFycmV0dA==?= Microsoft Frontpage 2 10th Nov 2006 11:00 PM
Center Table =?Utf-8?B?SmVmZg==?= Microsoft Word Document Management 1 22nd Nov 2005 09:30 PM
Center a Table in a Frame =?Utf-8?B?U2FtbXloYW1teQ==?= Microsoft Frontpage 1 8th Jul 2005 07:12 PM
Table is far right. How to center it. =?Utf-8?B?TXVsbGlnYW4xNTA5?= Microsoft Word New Users 1 1st Mar 2005 11:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:12 PM.