![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
i have one outer div containing two absolutely positioned inner divs. The height of the inner divs varies on the amount of content. Now the outer div's height should grow with the inner divs' height. how can this be achieved? example: http://www.bernd-liebermann.de/css_test.php |
#3
| |||
| |||
|
| Bernd Liebermann wrote: i have one outer div containing two absolutely positioned inner divs. The height of the inner divs varies on the amount of content. Now the outer div's height should grow with the inner divs' height. how can this be achieved? example: http://www.bernd-liebermann.de/css_test.php Absolutely positioned elements do not consume any layout space thus the inner divs will not add to the height of the outer div. Maybe you can achieve what you want by simply floating the inner divs. |
#4
| |||
| |||
|
|
Martin Honnen <mahotrash (AT) yahoo (DOT) de> wrote: Bernd Liebermann wrote: i have one outer div containing two absolutely positioned inner divs. The height of the inner divs varies on the amount of content. Now the outer div's height should grow with the inner divs' height. how can this be achieved? example: http://www.bernd-liebermann.de/css_test.php Absolutely positioned elements do not consume any layout space thus the inner divs will not add to the height of the outer div. Maybe you can achieve what you want by simply floating the inner divs. Martin makes a good point. I was able to achieve what (I think) you're after simply by making the .inner_left div's position relative (as opposed to absolute) and un-positioning .inner_right: |
#5
| |||
| |||
|
|
Dave Sisley wrote: No, that will not do it and is not what Martin suggested. With your way, the div.inner_right is rendered below the div.inner_left which is not what is requested. Try the float method applied to div.inner_left and a margin-left to div.inner_right: div.outer { border: solid black thin; width: 500px; } div.inner_left { float:left; width: 200px; height: 200px; background-color: red; } div.inner_right { margin-left:220px; width: 270px; background-color: yellow; } |
#6
| |||
| |||
|
|
Dave Sisley wrote: Martin Honnen <mahotrash (AT) yahoo (DOT) de> wrote: Bernd Liebermann wrote: i have one outer div containing two absolutely positioned inner divs. The height of the inner divs varies on the amount of content. Now the outer div's height should grow with the inner divs' height. how can this be achieved? example: http://www.bernd-liebermann.de/css_test.php Absolutely positioned elements do not consume any layout space thus the inner divs will not add to the height of the outer div. Maybe you can achieve what you want by simply floating the inner divs. Hi guys, |
|
Martin makes a good point. I was able to achieve what (I think) you're after simply by making the .inner_left div's position relative (as opposed to absolute) and un-positioning .inner_right: No, that will not do it and is not what Martin suggested. With your way, the div.inner_right is rendered below the div.inner_left which is not what is requested. Try the float method applied to div.inner_left and a margin-left to div.inner_right: div.outer { border: solid black thin; width: 500px; } div.inner_left { float:left; width: 200px; height: 200px; background-color: red; } div.inner_right { margin-left:220px; width: 270px; background-color: yellow; } |
#7
| |||
| |||
|
|
thanks for all your replys. Meanwhile i've found my own solution by positioning both inner divs relatively, defining a fixed height for the left box and setting the right div's top property to = -(height of the left div). Works here, as only the height of the right box varies. |
|
My first idea that the outer box should grow with the height of the inner boxes, no matter of the positioning scheme, still seems very intuitive to me and it's irritating that this is not the case. I understand that absolutely positioned elements are withdrawn from the normal element flow on sibling level, but to me it's somewhat counterlogical, that they don't consume layout space with regard to their containing element. But, this is how it is, so I have to live with it. |
#8
| |||
| |||
|
|
But of course when I actually tried hacking the original page, my solution looked terrible. As you note, the yellow div (.inner_right) is displayed below the red one (.inner_left). |
|
I can't get your solution to work either, though. Am I missing something? |
#9
| |||
| |||
|
|
Dave Sisley wrote: I can't get your solution to work either, though. Am I missing something? It WFM in Moz/FF, Opera and IE. You must be creating an error. Try copy and paste. |
![]() |
| Thread Tools | |
| Display Modes | |
| |