473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to center a table?

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 <tabletag, 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

Aug 28 '08 #1
8 7837
"Bob Altman" <rd*@nospam.nospamwrote in message
news:er**************@TK2MSFTNGP06.phx.gbl...
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;"
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 28 '08 #2
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Bob Altman" <rd*@nospam.nospamwrote in message
news:er**************@TK2MSFTNGP06.phx.gbl...
>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
Aug 28 '08 #3
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" <rd*@nospam.nospamwrote in message
news:OU**************@TK2MSFTNGP02.phx.gbl...
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>"Bob Altman" <rd*@nospam.nospamwrote in message
news:er**************@TK2MSFTNGP06.phx.gbl...
>>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

Aug 29 '08 #4
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:
ms****@microsoft.com.

==================================================
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" <rd*@nospam.nospam>
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 <tabletag, 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

Aug 29 '08 #5
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]" <st*****@online.microsoft.comwrote in message
news:ki**************@TK2MSFTNGHUB02.phx.gbl...
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:
ms****@microsoft.com.

==================================================
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" <rd*@nospam.nospam>
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 <tabletag, 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


Aug 29 '08 #6
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-***@nospam.nospamwrote in message
news:ue**************@TK2MSFTNGP02.phx.gbl...
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]" <st*****@online.microsoft.comwrote in message
news:ki**************@TK2MSFTNGHUB02.phx.gbl...
>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:
ms****@microsoft.com.

================================================= =
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" <rd*@nospam.nospam>
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 <tabletag, 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



Aug 29 '08 #7
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-***@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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-***@nospam.nospamwrote in message
news:ue**************@TK2MSFTNGP02.phx.gbl...
>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]" <st*****@online.microsoft.comwrote in message
news:ki**************@TK2MSFTNGHUB02.phx.gbl...
>>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:
ms****@microsoft.com.

================================================ ==
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" <rd*@nospam.nospam>
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 <tabletag, 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



Aug 29 '08 #8
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:
ms****@microsoft.com.

--------------------
>From: "Scott M." <s-***@nospam.nospam>
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-***@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>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-***@nospam.nospamwrote in message
news:ue**************@TK2MSFTNGP02.phx.gbl...
>>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]" <st*****@online.microsoft.comwrote in message
news:ki**************@TK2MSFTNGHUB02.phx.gbl.. .
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

Sep 1 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ajay | last post by:
I have following code for a slide menu but i twiked it to work for a single level menu. Open it in a Browser to get a clear picture. I have 2 Qs 1) How to make first entry as non-link. i.e i...
2
by: googley | last post by:
I'm starting a new thread for a problem that I ran into.. I'm trying to use STYLE SHEETS/CSS to update multiple table widths across many pages. I did get it working with one small problem that...
1
by: Richard | last post by:
I have a table that is about 100 rows long and within that table I have tons of links. The table takes about 2 seconds to load. I think javascript might help somehow. The problem is that in...
3
by: lovely_angel_for_you | last post by:
Hi, I have following link. By visitng first in IE, and then in Firefox, you would get to know my issue. http://lovely.angel.for.you.googlepages.com/test.htm...
4
by: Mark Rae | last post by:
Hi, Consider the following: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html...
7
by: Jeff | last post by:
hey gang. i have a question that is probably simple, and i could do it at one time, but i forget how. ok, how to explain i need to retrieve records from a db. which is no problem. but instead...
2
by: nino9stars | last post by:
Hello, I have just started messing with absolute positioning on webpages, and it definitely let's you do some creative things. Well, after much searching and help, I got the images I was using...
3
by: dubing | last post by:
Hi, I'm trying to do align table center in CSS like this. But it doesn't work. ..tx-gooffotoboek-pi1 table { text-align: center; } I can do <table align="center"but it's said deprecated....
3
by: RubbedLung | last post by:
Does anyone know how to get rid of this table offset. I'm using rounded corners and I can't seem to get the bottom to fit together. I've included a picture of the offset and the code. Thanks for your...
13
by: Stevo | last post by:
I've found that for IE6+, if you add the property text-align:center to a DIV, then *anything* inside it gets centered. That can be a table, an object/embed, another DIV, an image, or some text. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.