English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i'm trying to make a site where certain pages are tableless. i was to use pure css.. but have a 'table' style apperance. i've designed the page with several divs with fixed widths.. using the float feature. some of these div's are to contain user submitted content.. so.. i'm having an issue with embedded images either exceding the width of the div.. or getting cut off by the right side. is there anyway to have a div stretch to the width of its content.. and default to the fixed width if no content stretches it?

2007-11-28 15:33:21 · 3 answers · asked by d00b13630 1 in Computers & Internet Programming & Design

3 answers

Just leave your DIV with a set specific width, and then tell the DIV that all of the images displayed inside it will be no larger than a certain width:

#mydiv {
width:800px;
max-width: 750px;
}

This wont stretch the image, but it will scale it down if it's too large.

You could even do max-width:100%; and it should keep the images no larger than the DIV's width.

2007-11-28 15:40:40 · answer #1 · answered by strantheman 2 · 0 0

What you can do is to define a fixed-width

inside a variable-width
:


Some text here...




This way, the outer
will always be at least as wide as the inner
.

2007-11-28 15:56:52 · answer #2 · answered by NC 7 · 0 0

Yes. You want to use the min-width property as well as setting the display for your images to 'block'.

For example:

CSS:
.box-c { width: 900px; border: 1px solid #000; }
.box-c img { border: 1px solid red; display: block; }
.box-c .one, .box-c .two, .box-c .three {
min-width: 200px;
width: auto!important;
width: 200px;
float: left;
border: 1px solid green;
}

HTML:



hello
image

hello

hello



So here we have three columns with a min-width of 200px each. In the first column I've inserted an image of 300px -- this should give you a rough idea of what's going on. If you comment out the image from the HTML, the div shrinks back to 200px wide like the others.

One thing to note: IE6 does not support the min-width property. I've included a workaround in the CSS to accomodate IE6 (and it's really the best one out there):

.box-c .one, .box-c .two, .box-c .three {
min-width: 200px; /* read by standards compliant browers like Firefox and Safari */
width: auto!important; /* read by IE6 */
width: 200px; /* read by IE6 */
float: left;
border: 1px solid green;
}

Good luck!

2007-11-28 15:56:00 · answer #3 · answered by achtungbaby 3 · 0 0

fedest.com, questions and answers