Center a table in asp.net 2.0?

S

Scott M.

align="center" can still be used without any issues if you are using HTML or
XHTML Transitional (which are the most common forms of HTML and XML).
align="center" is considered to be deprecated by the World Wide Web
Consortium or W3C (the people who set the standards for HTML and other
technologies) and has been for about a decade, so using it in earlier
versions of .NET would still have put it in the deprecated "camp".

Because so many millions of web pages use the align attribute, the W3C
created a "flavor" of HTML which still allows for its use, the
"Transitional" flavor. If you are using this, then there is no problem
using align.

If you want to follow the "Strict" flavor, which says that align is
deprecated and can't be used, then you must use Cascading Style Sheets (CSS)
to do this:

<table id="something" style="margin-left: auto; margin-right: auto;">

Refer to these following links for more info:

http://www.captain.at/howto-css-horizontal-alignment.php
http://www.gtalbot.org/NvuSection/NvuWebDesignTips/HorizontalAlignment.html

-Scott
 
J

JustinCarmony

How do you center a table in visual studio 2005? It used to be align=center
but now it tells me it is an out of date method.

Just to make sure I'm understanding:

<table align="center">
<tr>
<td>blah</td>
<td>boo</td>
</tr>
</table>

You're trying to do something like that, correct?

align=center is a deprecated HTML table property. All table alignment
and formating should be done through CSS (Cascade Style Sheets). In
your style sheet, add this:

..tableClass { margin:0 auto; }

If you want to put it directly into your table, do this:

<table style="margin:0 auto">

What that is doing is saying I want the top and bottom margins to my
table (the space between your table and its surrounding objects) to be
0, but I want you to auto distribute the appropriate widths to the
sides.

Hope this helps.
 
G

Guest

You have to CSS style sheet and implement there and use class attribute to
specify style name or change the DOCType model to "Traditional" ...

Raj
 
K

Kat

How do you center a table in visual studio 2005? It used to be align=center
but now it tells me it is an out of date method.
 
J

James Irvine

Kat said:
How do you center a table in visual studio 2005? It used to be align=center
but now it tells me it is an out of date method.

I do it like this:

<div style="text-align:center">
<asp:Table ID="Table1" runat="server" >
etc...

But I'm new to this, so if this is an inferior way to go, someone please
point it out.

Also, what is telling you when you're using an 'out of date method'?
I'd like to get that warning too, but my compiler doesn't flag these
obsolete things I might have put in. thanks
 
J

James Irvine

Scott said:
That code won't work. text-align is for aligning text, not tables.

Thanks. I'm re-writing my code as we speak. So how do I avoid
accidentally putting in deprecated code?

I added <xhtmlConformance mode="Strict" /> to my Web.config file, but
it doesn't flag deprecated code (i.e. <center>) at compile time. Is
there a way I can be warned upfront about this?
 
S

Scott M.

HTML is not compiled code, so don't expect any compiler to tell you about
it.

Instead, add the appropriate DOCTYPE tag to your HTML or XHTML code, set the
schema for your page to validate against to the desired one and watch for
the red-wavy underlines in your HTML.

Having said that, as I stated earlier, there is nothing wrong with using
Transitional, which allows deprecated tags.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top