HighDots Forums  

Auto height for div is correct only when images do not float

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss Auto height for div is correct only when images do not float in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
inkswamp
 
Posts: n/a

Default Auto height for div is correct only when images do not float - 07-23-2006 , 02:59 AM






I've been using CSS for quite a while now but I have yet to master its
eccentricities. Here's something I recently ran across and if someone
could explain why this happens, I would appreciate it.

I've included code below. The code produces three divs, each with
height set to "auto." Within each div is an image. If I float the image
left or right, the height of the box does not accommodate the height of
the image automatically. If I don't apply a float to the image, the
height of box stretches out to accommodate the image height.

Why? I've searched and read as much as I can find about this and
nowhere have I found an explanation. Is this some esoteric aspect of
how CSS (or more specifically height:auto) works that I have yet to
understand or is it just a bug?

Here's the code. The first two examples create divs with seemingly
incorrect heights.


<div
style="padding:10px;width:100%;height:auto;backgro und-color:yellow;">
<img src="test.jpg" style="float:right;">
</div>

<br clear="all"><br><br>

<div
style="padding:10px;width:100%;height:auto;backgro und-color:yellow;">
<img src="test.jpg" style="float:left;">
</div>

<br clear="all"><br><br>

<div
style="padding:10px;width:100%;height:auto;backgro und-color:yellow;">
<img src="test.jpg">
</div>


Reply With Quote
  #2  
Old   
Steve Pugh
 
Posts: n/a

Default Re: Auto height for div is correct only when images do not float - 07-23-2006 , 04:25 AM






"inkswamp" <inkswamp (AT) gmail (DOT) com> wrote:

Quote:
I've been using CSS for quite a while now but I have yet to master its
eccentricities. Here's something I recently ran across and if someone
could explain why this happens, I would appreciate it.

I've included code below. The code produces three divs, each with
height set to "auto." Within each div is an image. If I float the image
left or right, the height of the box does not accommodate the height of
the image automatically. If I don't apply a float to the image, the
height of box stretches out to accommodate the image height.

Why?
Floating an element takes it out of the flow, hence it is not included
when the height if its parent is calculated.

Steve
--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <steve (AT) pugh (DOT) net> <http://steve.pugh.net/>


Reply With Quote
  #3  
Old   
Jim Moe
 
Posts: n/a

Default Re: Auto height for div is correct only when images do not float - 07-23-2006 , 03:44 PM



inkswamp wrote:
Quote:
I've been using CSS for quite a while now but I have yet to master its
eccentricities. Here's something I recently ran across and if someone
could explain why this happens, I would appreciate it.

See <http://css.maxdesign.com.au/>.

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.