HighDots Forums  

CSS : h-centering a div with of unspecified width

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss CSS : h-centering a div with of unspecified width in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Arnost Sobota
 
Posts: n/a

Default CSS : h-centering a div with of unspecified width - 06-11-2006 , 04:51 AM






Hello,

I am aware that the correct way to center a block-level element is to
set the left and right margins to auto.
However, this seems to only if the element to be centered has a width
explicitly specified.

Then, how can I center a div element that has no specified width?

As I understand it, the problem is that the default value for width is
100% and so the computed value for the "auto" left and rights margins is
zero.

Is there a way to minimize the width of a div (so that it fits exactly
its content) and make the horizontal centering work?

I'd greatly appreciate your expertise on this point!

Arnost

Reply With Quote
  #2  
Old   
Spartanicus
 
Posts: n/a

Default Re: CSS : h-centering a div with of unspecified width - 06-11-2006 , 10:35 AM






Arnost Sobota <sabotage (AT) minefi (DOT) gouv.fr> wrote:

Quote:
Is there a way to minimize the width of a div (so that it fits exactly
its content) and make the horizontal centering work?
2 ways:

1) Setting the display property to inline-block or inline-table (browser
support varies, search the archives), and then specify text-align:center
on the containing block.

2) Setting the display property to table invokes the familiar shrink to
fit table model, caveat: IE doesn't support the CSS table model.

--
Spartanicus


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.