views:

234

answers:

6

My css is this:

.stage{
    width:960px;
    background-image:url('stage.png');
    background-position:bottom;
    background-repeat:repeat-x;
    min-height:400px;
    float:left;
    text-align:center;
}

This places the background image of the bottom of the div, and the content is centered. But I cant figure out how to place the content in the bottom of the div.

The width is fixed, the height should expand if the content is higher than the div, but if the content is shorter, it should be placed in the bottom.

I have seen a few examples with at least 3 different divs to accomplish this, but is there a way of doing this with only one div in css? I don't want to place a div in the bottom of another div, all content inside the div should be in align to the bottom.

I wish it could be as simple as text-align:bottom;

+3  A: 

If you don't mind absolute/relative positioning use

.myContainer {
   position:relative; /* Needed so the inner divs position themselves relative to the container*/
}

.myInnerDiv {
    position:absolute;
    bottom:0px;
    text-align:center; /* To get the text to the center */
}

Then your html can be

<div class="myContainer">
    <div class="myInnerDiv">Content goes here</div>
</div>
Zoidberg
The problem is when the height of the inner content is higher than the outer box, the inner box grows, but not the outer...
Johan
That is an issue, but why is it a problem in your case? Can you elaborate on what exactly you want to accomplish?
Zoidberg
+2  A: 

You can do it with 1 div like this - your container div should be

position: relative;

and then style a paragraph (or an inner div) with

position: absolute;
bottom: 0px;
mbehan
If I do as you say, I get problem with the height, if the content is higher than `min-height` the `div` wont grow...
Johan
A: 

One way to achieve this would be to put the content in another div and position it absolutely within the .stage div.

.stage{position:relative;}

.stage .content{
 position:absolute;
 bottom:0;
 text-align:center;
}
Jamie Dixon
The problem is when the height of the inner content is higher than the outer box, the inner box grows, but not the outer...
Johan
A: 

vertical-align:bottom is the answer.

Ozan BAYRAM
I think thats only apply to `img`, see http://www.w3schools.com/Css/pr_pos_vertical-align.asp
Johan
A: 

Edit 2: You can do like this.

<div style="border: 1px solid yellow; width: 70%; height: 100%; position: relative; overflow:hidden">
    Outer
    <a style="border: 1px solid green; width: 100%; position: relative; float: left; margin-top: 5%;" href="#">      
        Comments are disabled for this post


    </a>
</div>

You can change any tag with <a>

See live demo here : http://jsbin.com/ajofu

metal-gear-solid
I have seen that, and they are using multiple divs.
Johan
in place of bottom div you can use any html tag but use same css
metal-gear-solid
@Jitendra. I'm not sure what you mean, but I don't want a div in the bottom, I want the content inside a div to be placed in the bottom of the div.
Johan
how u will put content in div? I mean in what tag like <p>
metal-gear-solid
@Jitendra. In all different tags, `<p>`, `<img>` `<object>` etc.
Johan
see my edited answer
metal-gear-solid
The problem is when the height of the inner content is higher than the outer box, the inner box grows, but not the outer...
Johan
see this now http://jsbin.com/ajofu
metal-gear-solid
i edited my answer
metal-gear-solid
A: 

This is kind of hackish, but it appears to work in Firefox, IE and Chrome (I don't have the other browsers to test it)

CSS

.myContainer {
 width:960px;
 background: #555 url('stage.png') bottom repeat-x;
 min-height:400px;
 float:left;
 text-align:center;
}

.myContainer img.spacer {
 height: 400px;
 width: 0;
 vertical-align: bottom;
 border: transparent 0px;
 text-align: left;
}

HTML

<div class="myContainer">
 <img alt="" class="spacer" /><br>
 blah blah blah blah blah blah blah blah blah blah blah blah
</div>
fudgey