Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > <center> deprecated

Reply
Thread Tools

<center> deprecated

 
 
Jeroen
Guest
Posts: n/a
 
      03-19-2005

The <center> element is not an element in html-4.01-strict,
and 'align' is not an attribute of a <div>.
The W3C states that I should use style="text-align: center",
but that only works for text and not for block-elements.

http://www.w3.org/TR/REC-html40/pres...ml#edef-CENTER

What should I use instead of <center> ???

--------------
The old way:

<body><center>
Hello y'all<BR>
<table style="width:400px; background-color:#DDDDDD">
<tr><td>hello</td><td>y'all</td></tr>
<tr><td>hello</td><td>y'all</td></tr>
<tr><td>hello</td><td>y'all</td></tr>
</table>
</center></body>
-------------

-------------
The new way proposed by W3C (the table isn't in the center):

<body style="text-align: center">
Hello y'all<BR>
<table style="width:400px; background-color:#DDDDDD">
<tr><td>hello</td><td>y'all</td></tr>
<tr><td>hello</td><td>y'all</td></tr>
<tr><td>hello</td><td>y'all</td></tr>
</table>
</body>
-------------


Greetings,

Jeroen
 
Reply With Quote
 
 
 
 
Steve Pugh
Guest
Posts: n/a
 
      03-19-2005
Jeroen <(E-Mail Removed)> wrote:

>The <center> element is not an element in html-4.01-strict,
>and 'align' is not an attribute of a <div>.
>The W3C states that I should use style="text-align: center",
>but that only works for text and not for block-elements.
>
>http://www.w3.org/TR/REC-html40/pres...ml#edef-CENTER
>
>What should I use instead of <center> ???


For block level elements use
margin-left: auto; margin-right: auto;
For inline level contents of block use
text-align: center;

IE5 is a problem. It doesn't support auto margins. But it does
incorrectly apply text-align to block level children.

So
body {text-align: center;}
table {margin-left: auto; margin-right: auto; text-align: left;}
Will center the table in IE5+ and browsers with goos CSS support.
(The text-align: left; is to stop the contents of the table being
centered within every cell.)

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <(E-Mail Removed)> <http://steve.pugh.net/>
 
Reply With Quote
 
 
 
 
Nick Theodorakis
Guest
Posts: n/a
 
      03-19-2005
On Sat, 19 Mar 2005 16:00:45 GMT, Jeroen <(E-Mail Removed)> wrote:

>
>The <center> element is not an element in html-4.01-strict,
>and 'align' is not an attribute of a <div>.
>The W3C states that I should use style="text-align: center",
>but that only works for text and not for block-elements.
>
>http://www.w3.org/TR/REC-html40/pres...ml#edef-CENTER
>
>What should I use instead of <center> ???



I have a couple of pages I haven't plugged in awhile:

<!--#include file="shameless.plug" -->

Centering block elements:
<http://theodorakis.net/blockcenter.html>

Centering tables:
<http://theodorakis.net/tablecentertest.html>

They are a bit long-winded, and a little dated in discussing a couple
of obsolete browsers, but I think you may find them useful. Also, pay
attention to the difference in rendering for browsers that do doctype
sniffing.

Nick

--
Nick Theodorakis
http://www.velocityreviews.com/forums/(E-Mail Removed)
contact form:
http://theodorakis.net/contact.html
 
Reply With Quote
 
Henry
Guest
Posts: n/a
 
      03-19-2005
Nick Theodorakis wrote:
> On Sat, 19 Mar 2005 16:00:45 GMT, Jeroen <(E-Mail Removed)> wrote:
>
>
>>The <center> element is not an element in html-4.01-strict,
>>and 'align' is not an attribute of a <div>.
>>The W3C states that I should use style="text-align: center",
>>but that only works for text and not for block-elements.
>>
>>http://www.w3.org/TR/REC-html40/pres...ml#edef-CENTER
>>
>>What should I use instead of <center> ???

>
>
>
> I have a couple of pages I haven't plugged in awhile:
>
> <!--#include file="shameless.plug" -->
>
> Centering block elements:
> <http://theodorakis.net/blockcenter.html>
>
> Centering tables:
> <http://theodorakis.net/tablecentertest.html>
>
> They are a bit long-winded, and a little dated in discussing a couple
> of obsolete browsers, but I think you may find them useful. Also, pay
> attention to the difference in rendering for browsers that do doctype
> sniffing.
>
> Nick
>



All of this crap because <center> is deprecated.


Just remind me, what was wrong with <center> in the first please!

Why it have to be replaced by some not very intuitive crap?


KISS is the key!

ALWAYS...

 
Reply With Quote
 
Leif K-Brooks
Guest
Posts: n/a
 
      03-20-2005
Henry wrote:
> Just remind me, what was wrong with <center> in the first please!
>
> Why it have to be replaced by some not very intuitive crap?


What's unintuitive about text-align:center for text? What's unintuitive
about putting margin:auto on block-level elements?

> KISS is the key!
>
> ALWAYS...


Right. The center element wasn't very simple.
 
Reply With Quote
 
Nick Theodorakis
Guest
Posts: n/a
 
      03-20-2005
On Sun, 20 Mar 2005 07:58:39 +0800, Henry <(E-Mail Removed)>
wrote:


[...]

>
>Just remind me, what was wrong with <center> in the first please!
>


Answer this: how should table cell *contents* be aligned if the table
is surrounded by <center>? Should they be left aligned or center
aligned?

>Why it have to be replaced by some not very intuitive crap?
>


There is actually nothing intuitive about the behavior of <center>. It
acts variously as an inline-alignment or sometimes as a block-level
alignment, depending on browser idiosycracies. I don't think even the
original specification was clear.

Nick
--
Nick Theodorakis
(E-Mail Removed)
contact form:
http://theodorakis.net/contact.html
 
Reply With Quote
 
Toby Inkster
Guest
Posts: n/a
 
      03-20-2005
Henry wrote:

> Just remind me, what was wrong with <center> in the first please!
> Why it have to be replaced by some not very intuitive crap?


As the others have said, CENTER was never an intuitive element.

Example:

<center>
Is this centred?
<table width="100%"><tr><td>Is this?</td></tr></table>
<p>Is this?</p>
</center>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 
Reply With Quote
 
Leif K-Brooks
Guest
Posts: n/a
 
      03-20-2005
Nick Theodorakis wrote:
> There is actually nothing intuitive about the behavior of <center>. It
> acts variously as an inline-alignment or sometimes as a block-level
> alignment, depending on browser idiosycracies. I don't think even the
> original specification was clear.


The original specification by Netscape
(http://wp.netscape.com/assist/net_si...xtensions.html) was
perfectly clear: <CENTER> was for centering text, and presumably would
have no effect on block-level elements.

Sadly, the HTML 4.01 standard
(http://www.w3.org/TR/html4/present/g....html#h-15.1.2) is more
confused on the subject. First, it says that the align attribute
"align[s] block elements [...] on the canvas"; later on, when discussing
the possible values for the attribute, it talks about "text lines". The
examples section says that the align attribute is equivalent to
text-align in CSS; unfortunately, the author doesn't seem to be very
knowledgeable about CSS, because a CSS example in the same section
claims that setting text-align:center on the body element would "center
the entire document".
 
Reply With Quote
 
Jens Lenge
Guest
Posts: n/a
 
      03-20-2005
"Steve Pugh" <(E-Mail Removed)> wrote:

> For block level elements use
> margin-left: auto; margin-right: auto;
> For inline level contents of block use
> text-align: center;


That makes me curious:
I have learned that I should generally prefer CSS formatting over HTML
formatting.
So when it comes to tables, should I consequently always use <table
style="margin:auto"> instead of <table align="center"> for centered
formatting?

Jens

 
Reply With Quote
 
Henry
Guest
Posts: n/a
 
      03-21-2005
Toby Inkster wrote:
> Henry wrote:
>
>
>>Just remind me, what was wrong with <center> in the first please!
>>Why it have to be replaced by some not very intuitive crap?

>
>
> As the others have said, CENTER was never an intuitive element.
>
> Example:
>
> <center>
> Is this centred?
> <table width="100%"><tr><td>Is this?</td></tr></table>
> <p>Is this?</p>
> </center>
>




<center>
Is this centred?
<table width="100%"><tr><td>Is this?<center>But this is centred
</center></td></tr></table>
<p>Is this? As well</p>
</center>


Also td could be centered separately.

Still new solution is creating more problems than old <center>.

Just a brief look on questions on this ng and there is a flood of them,
asking how to center this or that in css.

Centering anything in css seems to be a nightmare for beginners.

So many pages on the web trying to explain how to center anything.

If that margin: auto; and that text-align: center; would do the job, we
would not need all these articles and there would be not a nightmare on
this ng.

No wonder that MS feels that css2 has certain flaws and they are not
implementing it fully in next explorer.

I'm not the best friend of MS. Just in case.



Cheers...

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Deprecated methods: how important to fix? kaeli Java 3 08-24-2004 08:20 PM
XML/JDOM: Replacement for deprecated XMLOutputter ?? Bernd Oninger Java 1 06-10-2004 06:50 PM
deprecated getResources method David McDivitt Java 2 05-19-2004 01:49 PM
deprecated servlet session management: getSessionContext(); david Java 4 10-09-2003 12:22 AM
Deprecated warnings within deprecated code Barney Barumba Java 0 07-23-2003 12:46 AM



Advertisments