Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > centering without depreciated code

centering without depreciated code
Thread Tools
Junior Member
Join Date: Jun 2000
Location: Where the grass is greener
Status: Offline
Reply With Quote
Jan 29, 2002, 04:54 PM
 
Hello all,

I was wondering how one would go about centering an object or text without using W3C's depreciated HTML... I know there are lots of ways for like
<CENTER>
<DIV align="center">
<TD align="center">

but all of these methods are now scheduled to be axed... how do i get around this situation?

Thanks...
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Jan 29, 2002, 05:51 PM
 
For an inline object (text, images, etc.), use CSS to set its containing block's text-align property to center.

For a block-level object (P, DIV, and such) set the left and right margins to auto. The standard defines that when left and right margins are both set to auto, they're made equal (which centers the object). You can do this by manually setting margin-left:auto and margin-right:auto, or you can use the shortand "margin" property if you want.

Unfortunately, the auto-margin trick doesn't work with IE4/Windows. If this doesn't bother you, then fine. Otherwise, put your object in another tag that has text-align:center on it.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
ism
Grizzled Veteran
Join Date: Sep 2001
Status: Offline
Reply With Quote
Jan 29, 2002, 07:06 PM
 
Sam I am: in addition to milleniums answer (which is correct) you may want to check out these resources:

http://bluerobot.com/web/css/center1.html
http://bluerobot.com/web/css/center2.html

You may also want to subscribe to this newly created list for all your future css needs:


http://two.pairlist.net/mailman/listinfo/css-discuss

Ain't css fun?
     
Mac Elite
Join Date: Mar 2001
Status: Offline
Reply With Quote
Jan 29, 2002, 07:31 PM
 
Originally posted by Sam I Am:
<STRONG>depreciated</STRONG>
its deprecated, not depreciated. and just because it's deprecated doesn't mean that you are not allowed to use it and browsers won't understand it. it just means that they are recommending that you stop using it as soon as technically feasable.

i suppose you're already coding css 2.0 even though most browsers still doen't understand it and it's been out for a while already.

bottom line: don't worry about it.
     
Forum Regular
Join Date: Nov 2001
Location: Toronto Canada
Status: Offline
Reply With Quote
Jan 30, 2002, 08:12 PM
 
Actually in some cases you may find that a newer browser really doesn't understand the deprecated version. IE 6 windows, IE 5 mac and Netscape 6 all understand margin: auto, so you won't be totally out in the cold. If you're writing xhtml and using the doctype definition and also using img {display: block} to work around a little quirk in image displays you'll find that Mac IE 5, in particular doesn't understand &lt;center&gt;. In this case you'll have to do both. I usually ignore browsers older than 4.0 and do something like:

in the html: &lt;div class="center"&gt;

in the css: .center {text-align: center; margin: auto}. This should work in Netscape 4-6 and IE 4-6. Theoretically.

Welcome to the weird, wild world of supporting Netscape 4 and w3c standards simultaneously.
     
   
Thread Tools
Forum Links
Forum 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 On
Top
Privacy Policy
All times are GMT -5. The time now is 06:02 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2