In article <1nshwwnowyg1h$.dlg@funkenbusch.com>, "Erik Funkenbusch"
<erik@despam-funkenbusch.com> wrote:
[color=blue]
> Basically, Margin + Border + Padding + must equal the width of the
> containing block. In your case, the containing block is the BODY
> element, thus the content expands to the width of the body.
>
> You need to constrain some of the attributes of the box in order to do
> what you want. Either with margins, a containing div, or some other
> mechanism (such as absolute or relative positioning).[/color]
I've tried slapping a containing div around the div I'm trying to center,
but that didn't seem to accomplish anything, as that containing div just
expanded to fill the whole page.
Setting margins or padding or making the width absolute requires that I
know how big the text inside the box is going to be in advance. In this
case, I don't. It's a dynamically generated interface and I want to
display error messages in a box. Unfortunately, the length of
those messages is going to vary and I was hoping I could vary the size of
the box as well.
[color=blue][color=green]
>> Is there a way to tell a block-level element that it should only be as
>> wide as it has to be? I've looked in all of the documentation I'm
>> aware of and I can't seem to find a way, so it seems to me that the
>> answer is probably no. Am I missing something?[/color]
>
> Again, you need to really understand the box model. I can't stress this
> enough. It's really easy to gloss over it and think you understand.
> There are some subtleties to it that aren't obvious at first.[/color]
I've read about the box model (including relevant sections of the document
at
http://www.w3.org/TR/REC-CSS2/. As I said above, it doesn't seem to me
that there is a way to contstrain the width of the box based on the
required width of its content. Is that true, or is there a subtlety that
I'm missing?
Cheers,
Luke