473,408 Members | 2,450 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,408 software developers and data experts.

Whats the new way to center a table

Hi,

I have read the you should no longer use 'align="center"' when you
want to center a table or something other.
So I asked myself what should I use than. I found something that you
should use styles. But they used a attribute that is only for text
elements.
So can someone give me an example or an url where I can find further
information.

I first discovered this problem while testing my application with
Mozilla 1.3.1. The align=center for my tables had no effect. When I
put the table in a <div align=center> than all works fine.

cu
Bjoern
Jul 20 '05 #1
9 10674
Bjoern Wolfgardt <14*************************@posting.google.com> wrote in
comp.infosystems.www.authoring.html:
I have read the you should no longer use 'align="center"' when you
want to center a table or something other.
So I asked myself what should I use than. I found something that you
should use styles. But they used a attribute that is only for text
elements.
So can someone give me an example or an url where I can find further
information.


http://stone.thecoreworlds.net/www/centre/

Regards,
Geoff

--
http://www.allmyfaqs.com/faq.pl?Geoff_Ball
http://www.allmyfaqs.com/faq.pl?Web_Core_References
http://www.allmyfaqs.com/faq.pl?How_to_post
Jul 20 '05 #2
In article <14*************************@posting.google.com> in
comp.infosystems.www.authoring.html, Bjoern Wolfgardt
<aa*****@gmx.de> wrote:
can someone give me an example or an url where I can find further
information.


http://theodorakis.net/tablecentertest.html

It's the goods!

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
validator: http://jigsaw.w3.org/css-validator/
Jul 20 '05 #3
Stan Brown <th************@fastmail.fm> wrote:
http://stone.thecoreworlds.net/www/centre/


That's a lovely resource, but it doesn't actually answer the
question. :-(


It does, but this is a question that cannot be answered in
straightforward way as it depends on a number of variables (doctype,
<IE6 etc.>.

The page answers the question by explaining how it works in the "Teach a
man to fish" tradition.
Headless

Jul 20 '05 #4
LOL...

Web development is so confusing.

The CSS Way works fine with Mozilla. But not with IE 6. And Mozilla
doesn't use the align=center attribute but IE 6 does.

I think I will use both like this:
<table align=center style="MARGIN-LEFT:auto;MARGIN-RIGHT:auto"
border="1">

cu
Bjoern Wolfgardt

Stan Brown <th************@fastmail.fm> wrote in message news:<MP************************@news.odyssey.net> ...
In article <14*************************@posting.google.com> in
comp.infosystems.www.authoring.html, Bjoern Wolfgardt
<aa*****@gmx.de> wrote:
can someone give me an example or an url where I can find further
information.


http://theodorakis.net/tablecentertest.html

It's the goods!

Jul 20 '05 #5
Stan Brown wrote:
In article <1234666.PYKUYFuaPT@geoffball> in
comp.infosystems.www.authoring.html, Geoff Ball <ge********@shaw.ca>
wrote:
http://stone.thecoreworlds.net/www/centre/


That's a lovely resource, but it doesn't actually answer the
question. :-(


Really?

Quote:
Block level content includes such elements as <h1>, <h2>, <p>, <table> (but
^^^^^
see IE Bugs), and <div>. To centre block level elements...

--
David Dorward http://david.us-lot.org/
Jul 20 '05 #6
Bjoern Wolfgardt wrote:

Please direct your attention to: http://www.allmyfaqs.com/faq.pl?How_to_post
The CSS Way works fine with Mozilla. But not with IE 6. And Mozilla
doesn't use the align=center attribute but IE 6 does. I think I will use both like this:
<table align=center style="MARGIN-LEFT:auto;MARGIN-RIGHT:auto"
border="1">


MSIE is broken. You have to force it in to standards mode or take further
steps to centre block level content in it. See:
http://david.us-lot.org/www/centre/#ie

--
David Dorward http://david.us-lot.org/
Jul 20 '05 #7
In article <bf*******************@news.demon.co.uk> in
comp.infosystems.www.authoring.html, David Dorward
<do*****@yahoo.com> wrote:
Stan Brown wrote:
In article <1234666.PYKUYFuaPT@geoffball> in
comp.infosystems.www.authoring.html, Geoff Ball <ge********@shaw.ca>
wrote:
http://stone.thecoreworlds.net/www/centre/


That's a lovely resource, but it doesn't actually answer the
question. :-(


Really?

Quote:
Block level content includes such elements as <h1>, <h2>, <p>, <table> (but
^^^^^
see IE Bugs), and <div>. To centre block level elements...


My apologies. I overlooked that.

I think Nick Theodorakis' page is much better for the OP's question
because it goes much more thoroughly into the specific issues of
tables, but I agree that the stone page does mention tables.

I think there is one problem with the suggested solution, which was

<div style="text-align: center;">
<div style="text-align: left; margin: 1em auto; width: 50%;">
</div>
</div>

When centering a table, if you do

<div style="text-align: center;">
<table style="text-align: left; margin: 1em auto; width: 50%;">
</table>
</div>

then doesn't that cause the <th> elements also to be left aligned,
by inheritance?

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
validator: http://jigsaw.w3.org/css-validator/
Jul 20 '05 #8
Stan Brown wrote:
I think Nick Theodorakis' page is much better for the OP's question
because it goes much more thoroughly into the specific issues of
tables, but I agree that the stone page does mention tables.
Other then the <th> issue you mention below, there aren't any table specific
issues (at least with CSS centring methods). They are just block level
elements.
When centering a table, if you do

<div style="text-align: center;">
<table style="text-align: left; margin: 1em auto; width: 50%;">
</table>
</div>

then doesn't that cause the <th> elements also to be left aligned,
by inheritance?


Nothing preventing you from having:

..tableWrapper { text-align: center; }
table { text-align: left; margin: auto 1em; }
th { text-align: center; }
--
David Dorward http://david.us-lot.org/
Jul 20 '05 #9
In article <bf*******************@news.demon.co.uk> in
comp.infosystems.www.authoring.html, David Dorward
<do*****@yahoo.com> wrote:
Nothing preventing you from having:

.tableWrapper { text-align: center; }
table { text-align: left; margin: auto 1em; }
th { text-align: center; }


Agreed -- my point was that the page doesn't even raise the issue
and someone who posts "how do I center a table?" isn't likely to
guess that it's needed.

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
validator: http://jigsaw.w3.org/css-validator/
Jul 20 '05 #10

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

Similar topics

6
by: adam | last post by:
The folowing code produces an error althought i cant understand why it does this can any one help? THANKS ERROR = Notice: Undefined variable: tab in C:\Inetpub\wwwroot\carpound\table\table1.php...
2
by: Jim | last post by:
Im getting way too many rows retured..what its trying to do is insert a 0 for revenue for months 7 - 12 (aka July through December) for each of these cost centers for each payor type..Im getting a...
0
by: PayPal | last post by:
<HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft DHTML Editing Control"> <TITLE></TITLE> </HEAD> <BODY> <STYLE type=text/css> ..dummy {} BODY, TD {font-family:...
3
by: francisco lopez | last post by:
I hope not sent I twice. ok here is my problem, the javascript form validation works perfect during I put a emaildirection in the <form action:""> comand, like this: <form...
7
by: ALI-R | last post by:
Hi All, I have two user controls (header and footer) ,,which I've placed in an HTML Table in a page.I set the **align="center"** in the table and the table still is on the left side of the page...
2
by: yangtono | last post by:
Hi, I am creating a table to list some data. The table is using a sorting and highlight function that I found from the net. I can't attach image here, basically html will wrap the heading,...
14
by: gaijinco | last post by:
I was a hobbist web coder for years but I had to sidestep for a while. Now I'm trying to return to it and I'm trying to clarify how am I supposed to do somethings with CSS v.s. HTML and I'm...
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. ...
8
by: Bob Altman | last post by:
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.