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
.
Try position:fixed; bottom:0; . This will make your div to stay fixed at the bottom.
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.
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.
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.
#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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With