I managed to center 2 divs
using the power of flex
, and now I want to introduce a third div
at the bottom of the page, just like in the image below:
https://i.sstatic.net/pQleWm.jpg
(I need the first two divs
to stay centered based on their parent element without being affected by the third div
.)
I attempted to achieve this, but unfortunately, the third div
kept getting pushed off-screen. I can't reduce the height of #centerWrapper
below 100%
either because then the alignment of the first two divs
would be compromised.
*,
*:before,
*:after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body,
#parent {
width: 100%;
height: 100%;
}
#centerWrapper {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
#centerWrapper * {
width: 100px;
height: 100px;
}
#firstChild {
background-color: brown;
}
#secondChild {
background-color: lightblue;
}
#thirdChild {
background-color: greenyellow;
}
<div id="parent">
<div id="centerWrapper">
<div id="firstChild"></div>
<div id="secondChild"></div>
</div>
<div id="thirdChild"></div>
</div>