tags:

views:

20

answers:

1

When I have a table with a width of 800px and an image within it with a width of 1000px, the table will expand to encompass the image. When I have a div with a width of 800px and the same image within it, the div will remain at 800px and the image will cross over the div's border. How do I get a div to replicate this expand-when-necessary nature of a table?

+2  A: 

Set the width to auto and the min-width to 800px if you don't have to support IE6.

Like this

#mydiv {
    width:auto;
    min-width:800px;
}
Octavian Damiean
When I do that, the div's width will be the page width, not 800px?
Tom
For IE6 support define another rule `* html #mydiv { width:800px; }` since only IE6 evaluates `* html` rules and treats `width` like `max-width`.
LeguRi