tags:

views:

3177

answers:

3

I have outer div and inner div. I need to place inner div at the bottom of the outer one.

Outer div is elastic (width: 70% for example). I also need to center inner block.

Simple model of described make-up is shown on the picture below:

alt text

+13  A: 

Tested and working on Firefox 3, Chrome 1, and IE 6, 7 and 8:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                      "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html><body>
<div style='border: 1px solid yellow; width: 70%;
            height: 100px; position: relative;'>
    Outer
    <div style='border: 1px solid green;
                position: absolute; left: 0; width: 100%; bottom: 0;'>
        <div style='border: 1px solid magenta; width: 100px;
                    height: 30px; margin: 0 auto; text-align: center'>
            Inner
        </div>
    </div>
</div>
</body>
</html>
RichieHindle
Thank you, your solution is almost correct. I only had to add "//margin-left: -40px" to green block's style for IE. Without this hack with margin-left attribute your green block was disposed left in IE7. Can anyone explain where this 40px comes from?
Roman
IE7 was horizontally positioning the green div after the word "Outer". I've updated the code to specify "left: 0".
RichieHindle
This is it. Nice!
Roman
+4  A: 

You need a wrapping div for the bottom one, in order to center it.

<style>
   /* making it look like your nice illustration */
   #outer { width: 300px; height: 200px; background: #f2f2cc; border: 1px solid #c0c0c0; }
   #inner { width: 50px; height: 40px; background: #ff0080; border: 1px solid #800000; }

   /* positioning the boxes correctly */
   #outer { position: relative; }
   #wrapper { position: absolute; bottom: 3px; width: 100%; }
   #inner { margin: 0 auto; }
</style>


<div id="outer">
   <div id="wrapper"><div id="inner"></div></div>
</div>
Magnar
A: 

Works well on all browsers including ie6.

<style>
    #outer{
        width: 70%;
        background-color: #F2F2CC;
        border: 1px solid #C0C0C0;
        height: 500px;
        position: relative;
        text-align: center;
    }

    #inner{
        background-color: #FF0080;
        border: 1px solid black;
        width: 30px;
        height: 20px;

        /* Position at the bottom */
        position: relative;
        top: 95%;

        /* Center */
        margin: 0 auto;
        text-align: left;
    }
</style>

<div id="outer">
    <div id="inner">
 </div>
</div>
Dmitri Farkov