Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- possible to make div width match content?
April 1, 2006, 2:08 am
rate this thread
I'm trying to make a <div>, but from what I've observed, be default, it
trys to consume the most width possible.
What 'm have trouble doing is make it take the /minmal/ space possible,
like a table without any specified width.
What I'm really getting at is I'm trying to have a simple <div> with
left aligned text but be centered on the screen.
I've tried many variants of the following:
<div style="text-align: left">
Text that should be Left aligned, but centered on the screen.
So it looks like this
| Text that should be Left aligned, but centered on |
| the screen. |
^----- screne border -------------------------------------------------^
Thanks for any help. This is really driving me up the wall, especialyl
since I've bene workign with html since 1997! arrgh! :-)
Re: possible to make div width match content?
That would be "width:0", not much point I would think.
That would be the table-layout:auto width mechanism:
A table without specified width would extend the width of the table to
100% of it's containing block, and then wrap the text within it, not
what you've drawn above.
To achieve what you've drawn you'd need
<p style="width:25em;margin-left:auto;margin-right:auto">Text that
should be Left aligned, but centered on the screen.</p>
- » Is there any way to make destination URL see a different referer?
- — Previous thread in » HTML Markup Language