views:

124

answers:

3

The div inside another div picture and code below. Because there will be text and images of the parent div. And red div will be the last element of the parent div.

alt text

<div style="width: 200px; height: 150px; border: 1px solid black;">
    <div style="width: 100%; height: 50px; border: 1px solid red;">
    </div>
</div>
+2  A: 

Make the outer div position="relative" and the inner div position="absolute" and set it's bottom="0".

Fermin
+1  A: 
<div style="width: 200px; height: 150px; border: 1px solid black;position:relative">
    <div style="width: 100%; height: 50px; border: 1px solid red;position:absolute;bottom:0">
    </div>
</div>
RegDwight
+2  A: 

This is one way

<div style="position: relative; width: 200px; height: 150px; border: 1px solid black;">
    <div style="position: absolute; bottom: 0; width: 100%; height: 50px; border: 1px solid red;">
    </div>
</div>

But because the inner div is positioned absolutely, you'll always have to worry about other content in the outer div overlapping it (and you'll always have to set fixed heights).

If you can do it, it's better to make that inner div the last DOM object in your outer div and have it set to "clear: both".

Jon Smock
Thanks for your explanation and IE Hack (if i am not wrong you added **width: 100% for IE Hack).
uzay95
Nope, the width: 100% was there in your original - I didn't add it.
Jon Smock
I tried to bold the sections I changed, but the Markdown doesn't apply inside code blocks :-P
Jon Smock
:) Actually i couldn't get how we are hacking IE with symbols, thats why i thought it is IE Hacking :)
uzay95