How to arrange two divs one on top of the other at the bottom of the parent?

2 answers

You can use Flexbox. With justify-content: flex-endand, you can move the contents to the end of the parent element , so if you want to put another child on top of the parent, you can use margin-bottom: auto. This applies if you are setting flex-direction: columnfor the parent.

.content {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.main {
  margin-bottom: auto;
  border: 1px solid black;
}
.box {
  background: lightblue;
  margin: 5px;
}
<div class="content">
  <div class="main">Lorem ipsum dolor.</div>
  <div class="box">One</div>
  <div class="box">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Obcaecati vel molestiae dolores, ad, nulla harum tenetur minima aperiam debitis id atque fugit, modi error et magni eius repellendus saepe. Vero?</div>
</div>
Run codeHide result
+4
source

You can wrap both of them in a div and set the absolute position style for that div, rather than applying them individually.

works [Fiddle] [1]

[1]: https://jsfiddle.net/gd5pqky7/
0
source

All Articles