Forum Moderators: open

Message Too Old, No Replies

Div's behavior

when it has another div in it

         

gasell

1:37 pm on Dec 18, 2004 (gmt 0)

10+ Year Member



So I have one div in another and neither of them have height specified. When I put content in the inner div then it fits its height to content. But the outer div won't grow to nest the inner one in firefox. It will display as a horisontal line. In IE and Opera it stretches and nests the inner one correctly.
Now which of these behaviors is actually right and which one is browsers mistake? Also is there a way how I can force all browsers to stretch the outer div according to the size of inner one?
Hope you understand what I mean..

Birdman

1:52 pm on Dec 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It sounds to me like you have floated the inner div(or it's content). That will cause your problem because floated elements are taken out of the flow. In other words, their space is not calculated in the normal way.

You can add an element to clear the floats, which will stretch the outer div.

Example:

<div>
<div style="float: left;">
content...
</div>
<div style="clear: both;"></div>
</div>

[edited by: Birdman at 2:30 pm (utc) on Dec. 18, 2004]

gasell

2:27 pm on Dec 18, 2004 (gmt 0)

10+ Year Member



I actually didn't get much of your explanation but it works :)
Never dealt with clear before.

[edited by: gasell at 3:11 pm (utc) on Dec. 18, 2004]

Birdman

2:33 pm on Dec 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[google.com...]

You will find much info on the topic at the link above.

Regards

gasell

3:12 pm on Dec 18, 2004 (gmt 0)

10+ Year Member



But can I have repeated background in outer div when the only content in it is two divs? Right now firefox won't display it.

valder

3:25 pm on Dec 18, 2004 (gmt 0)

10+ Year Member



Hi, I don't seem to understand the problem and I can't reproduce it, but I'm wondering if this is an issues I should be aware of, so I'm posting to try to understand the issue.

As I understand what you're saying, the problem is that the following code will show as a horizontal line, is this correct?

<div><div>line1<br />line2<br />line3</div></div>

I must have misunderstood your question, because this seems to show fine in firefox, at least 1.0 on linux.

gasell

3:30 pm on Dec 18, 2004 (gmt 0)

10+ Year Member



Yes, that was the problem but you'll see it only when outer div has background or border defined. I had border and instead of it I saw same colour line.

valder

3:32 pm on Dec 18, 2004 (gmt 0)

10+ Year Member



Sorry, checked it with background now, and I see your problem :)