Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aligning a child div centered/bottom in parent

I'd like to align a child div inside a parent div (header-image as background image) centered vertical and horizontally to the bottom.

<div id="header-image">
    <div class="row">
        ... Content
    </div>
</div>

I found a solution for horizontal centering:

<div style="position: absolute; left: 50%;">
    <div style="position: relative; left: -50%;">
        ... content
    </div>
</div>

But no idea how to get the content to the bottom (works only with position:absolute)

For better understanding on http://webstopp.de/ you can see a header-image and some text in it but the text has to be on bottom of the header-image div.

like image 349
toddiHH Avatar asked Jun 06 '13 16:06

toddiHH


People also ask

How do you align a div at the bottom of the page?

Try position:fixed; bottom:0; . This will make your div to stay fixed at the bottom.

How do I position something at the bottom of a page in CSS?

If position: absolute; or position: fixed; - the bottom property sets the bottom edge of an element to a unit above/below the bottom edge of its nearest positioned ancestor. If position: relative; - the bottom property makes the element's bottom edge to move above/below its normal position.

How do I align my child div horizontally?

We can set the child element as an in-line element, display: inline-block; , and then set the father element as text-align: center; , so that the child element can be horizontally centered.

How do I align text at the bottom of the container?

display:flex on the container. flex-direction: column will distribute children from top to bottom. margin-top: auto to the element that you want to stick at the bottom, flex will apply all the free space above.


1 Answers

#header-image {
    background: url("http://placehold.it/200x200&text=[banner img]") no-repeat;
    height: 200px;
    width: 200px;
    position: relative;
    left: 0;
    bottom:0;
}
.row {
    position: absolute;
    left: 50%;
    bottom:0;
}
.inner {
    position: relative;
    left: -50%
}

Fiddle

like image 178
Khanh TO Avatar answered Sep 27 '22 03:09

Khanh TO