Replacement for <div align="center">

B

Ben Amada

Hello,

When centering a block of HTML, in the past, I've always used:

<div align="center"> ... </div>

However, in VS 2005, I get the following warning:

"Validation (XHTML 1.0 Transitional): Attribute 'align' is considered
outdated. A newer construct is recommended."

What is the newer construct I should use?

Thanks!
Ben
 
L

Lau Lei Cheong

Actually, W3C recommands you to use CSS style(i.e.: style="TEXT-ALIGN:
center") instead.
 
B

Ben Amada

Lau said:
Actually, W3C recommands you to use CSS style(i.e.: style="TEXT-ALIGN:
center") instead.

Hi,

Thanks for the tip. Actually, I did try using the text-align style once,
however I ran into a problem where inside the <div> tag, I inserted a
<table> and the table correctly centers in IE, however in Firefox, the table
renders on the left side of the browser. Basically the HTML looks like:

<div style="text-align:center">
<h1>Header</h1>
<table> ... </table>
</div>

The contents of <h1> correctly centers in Firefox, however the entire table
is left-justified.

Any ideas on how to resolve this?

Thanks,
Ben
 
A

Andrea Zani

Ben Amada said:
Any ideas on how to resolve this?

Thanks,
Ben

Try this code:

<div style="text-align:center;">
<h1>Header</h1>
<table style="margin-right: auto; margin-left: auto;">
<tr><td>r1</td></tr>
<tr><td>r2</td></tr>
</table>
</div>
 
S

Scott M.

Yes it has. And so has <FONT> and many other tags, but we use them every
day because they are part of the "HTML 4.01 Transitional" DTD. This is what
"Transitional" means, it means that you can use deprecated code AND CSS. If
you were using "HTML 4.01 Strict", you couldn't do that, but most people use
Transitional because support for the deprecated tags is still very
widespread.
 
K

Kevin Spencer

Well, Scott, let me remind you that "deprecated" is a word which indicates a
kind of warning, if you will, that something is not going to last. The word
"transitional" indicates that something is being supported during a
transition phase from one set of standards to another, and a transitional
phase lasts only as long as the transition.

Yes, browsers may support this tag (and other deprected tags and elements)
for some years to come, but eventually they will not, and in the meantime,
being deprecated, it (and other deprecated tags) may not work as well over
time, as they come into (possible) conflict with emerging standards.

Bearing this in mind, and being a developer who doesn't want to overburden
himself in the future, while I am not going back over everything I've
created to date and updating it, neither do I want to have to do so all at
one painful whack in the future. So, my personal strategy is to work with
the new standards when I am doing new work, and to avoid deprecated
standards as much as possible. Older work I leave as is, unless I have to do
some maintenance or other upgrade type work on it, in which case I may, if
convenient, do a bit of standards upgrading as well.

Of course, this is not something I am touting as "the right way" or "the
only way" to do things, but I hope you may find it food for thought.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
 
S

Scott M.

Yes Kevin, I'm aware of all that. My feeling is that the bulk of the
deprecated tags have been that way for nearly a decade. I can't forsee any
time in the future where an HTML parser won't understand <CENTER> and
<FONT>, it's just not going to happen because of the 100's of millions of
pages that have these tags on them.

This is why we have the choice to use Transitional or Strict. I guess what
I'm saying is that I believe Transitional will be around forever.
 
K

Kevin Spencer

Sure Scott. Seems Bill Gates once said that a computer would never need more
than a megabyte of RAM, now that I think of it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
 
B

Ben Amada

Andrea said:
Try this code:

<div style="text-align:center;">
<h1>Header</h1>
<table style="margin-right: auto; margin-left: auto;">
<tr><td>r1</td></tr>
<tr><td>r2</td></tr>
</table>
</div>

Hi Andrea,

That works great :)

Thank you,
Ben
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top