Previous Message
Next Message

centering elements via margin: auto

Sent by Michael Leibson on 30 June 2007 16:04


Thank-you, Josue, and also David, for your helpful replies.  

I've come across this code before, but not - yet - in Eric's book (it's a pretty dense study, for
someone starting from scratch!).  I gather that "{margin 0 " refers to positioning, and (maybe)
means the margin should be at maximum left.  But I don't understand how "0" and "auto" work
together.  I've also read that "body {text-align: center;}" requires explicit text-align statements
in all children where one doesn't want text to be aligned to centre.

I've experienced a few frustrations with Eric's book: for one, the Index is pretty sparse -- for
example, I can't find any reference to 'centering a block element vertically'.  As well, there are
almost no references to how to solve particular problems (eg, vertically centering a block element)
-- I had to find those in other texts (eg, Web Design In A Nutshell).

That's why I greatly appreciate these replies!

All the best,

Michael


Hey, Michael, create a container for your layout (a div that will house everything else). Use this
code, assuming that div is called container


body {text-align: center;}
#container {margin 0 auto; text-align: left;}



This is covered in the book. Maybe in the chapter on positioning. Hope this helps.







      Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the
All-new Yahoo! Mail at http://mrd.mail.yahoo.com/try_beta?.intl=ca
______________________________________________________________________
css-discuss [EMAIL-REMOVED]]
http://www.css-discuss.org/mailman/listinfo/css-d
IE7 information -- http://css-discuss.incutio.com/?page=IE7
List wiki/FAQ -- http://css-discuss.incutio.com/
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
Previous Message
Next Message

Message thread:

Possibly related: