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.
<div style="width: 200px; height: 150px; border: 1px solid black;"> <div style="width: 100%; height: 50px; border: 1px solid red;"> </div> </div>
Set the position of div at the bottom of its container can be done using bottom, and position property. Set position value to absolute and bottom value to zero to placed a div at the bottom of container.
Try position:fixed; bottom:0; . This will make your div to stay fixed at the bottom.
Use the text-align property to align the inner content of the block element. Use the bottom and left properties. The bottom property specifies the bottom position of an element along with the position property. The left property specifies the left position of an element along with the position property.
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.
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".
A flexbox way.
HTML:
<div class="parent"> <div>Images, text, buttons oh my!</div> <div>Bottom</div> </div>
CSS:
.parent { display: flex; flex-direction: column; justify-content: space-between; } /* not necessary, just to visualize it */ .parent { height: 500px; border: 1px solid black; } .parent div { border: 1px solid red; }
Edit:
Source - Flexbox Guide
Browser support for flexbox - Caniuse
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