![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
The crux of the problem I'm having is that I'm unable to stop a block-level element from filling up the entire available width without making it a float, and once it's a float, I'm uable to center it. |
|
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? |
#3
| |||
| |||
|
|
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. |
#4
| |||
| |||
|
|
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). |
|
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? 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. |
#5
| |||
| |||
|
|
In article <1nshwwnowyg1h$.dlg (AT) funkenbusch (DOT) com>, "Erik Funkenbusch" erik (AT) despam-funkenbusch (DOT) com> wrote: 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). 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. [snip] |
#6
| |||
| |||
|
|
Is there a way to tell a block-level element that it should only be as wide as it has to be? display: table-cell ; only works in Opera afaik |
#7
| |||
| |||
|
|
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. |
#8
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |