size a DIV as large as needed to fit contents

J

JezB

I have a DIV whose contents varies in size according to data. How can I size
the DIV precisely to fit it's contents ?
 
D

Darren Clark

what do you mean ?

the only thing you can really do design wize.... is to allow full expansion
to scale with the window.

OR constict the wide and let the length flow
 
J

JezB

Any suggestions are very welcome - thanks.

Eliyahu Goldin said:
Ok, I am taking a risk of getting into your "Block sender" list.

If you use a table, you can put the content you want to be inside the div
into a td. You can format td itself instead of div or you can put a div into
the td with width and height=100%. The td will adjust its size according to
data.

If you don't want table-related suggestions anymore, put a note in your
messages "no tables please".

Eliyahu
 
E

Eliyahu Goldin

Ok, I am taking a risk of getting into your "Block sender" list.

If you use a table, you can put the content you want to be inside the div
into a td. You can format td itself instead of div or you can put a div into
the td with width and height=100%. The td will adjust its size according to
data.

If you don't want table-related suggestions anymore, put a note in your
messages "no tables please".

Eliyahu
 
K

Kevin Spencer

Don't size it at all. Then it will precisely fit its contents.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
J

JezB

Good idea! But that only seems to work for height, the width of my DIV seems
to default to the full browser width.
 
K

Kevin Spencer

It is a block element. It will expand horizontally to fit its container.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
J

John Saunders

JezB said:
Good idea! But that only seems to work for height, the width of my DIV seems
to default to the full browser width.

Just for fun, try style="width: 0" or style="width: 0%".
 
J

JezB

But that's exactly what I dont want - I want it only wide enough to fit its
contents.
 
K

Kevin Spencer

Put it into a table cell.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
J

JezB

J

JezB

Our company standards state that "use of tables is to be discouraged" but
goes on to say "light use of tables to solve specific problems is not
condemned - the developer must simply be aware of and document the
implications of table use" - so perhaps in this special instance I can use
them.

Thanks.
 
E

Eliyahu Goldin

You can choose when you have a choice. So far you don't. On this newsgroup
by now you have 2 people with table suggestions and none with css one.

Thank you for the links. Note, that the first one is based on the author's
practical experience, whereas the second one is just an abstract statement.

Anyway, wish you good luck on either way. It would be nice if you could tell
us about the solution.

Eliyahu
 
K

Kevin Spencer

Patience is a virtue, Eliyahu!

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top