[css-d] Centering DIV block without setting its width.

2008-04-04 Thread Yuri
A newbie question:

I am trying to center a DIV block without specifying its width
explicitly: I'd like the width to depend on DIV's contents. I set
'display' property to 'table' as shown below:


html
  headtitleCentering DIV/title/head
  body
div style=margin-left: auto; margin-right: auto; display: table
  hello!
/div
  /body
/html


This works (at least in Firefox and Opera) but I'm not sure if this is a
correct technique.  Is there a right way do center a block without
setting its width property explicitly?

Thanks in advance,
Yuri


__
css-discuss [EMAIL PROTECTED]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
List policies -- http://css-discuss.org/policies.html
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/


Re: [css-d] Centering DIV block without setting its width.

2008-04-04 Thread Yuri
Hi Benjamin,

Thank you for your response.

 If you want the text (and other inline elements) inside this DIV to be
 centered you could set text-align to center. However, I'm guessing you
 don't want that precisely. 

This is true, I'd like only the container to be centered.

 I'm not sure I understand why you wouldn't
 want to set a width explicitly if you know you want it to be centered.

The DIV block holds a table with varying number of columns and some 
other elements that I'd like to keep together with the table.  If it were 
just a table it would not be a problem because of the way the widths are 
computed.

http://www.w3.org/TR/CSS21/tables.html#width-layout

 Oh, and the display: table settings are not very well supported at the
 moment. I'd steer clear of them for now.

This is my concern too.  I'll probably think of something different.  Thanks 
again for your response.

Yuri

__
css-discuss [EMAIL PROTECTED]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
List policies -- http://css-discuss.org/policies.html
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/