checkout the fiddle https://jsfiddle.net/3531chbz/1/
The trick is that you should not give an attribute position:for the second div, i.e. #div2, therefore, in this case, the child in the second div will take a position with his great parent,
you must also change the input position to position:absolute
HTML
<div id='div1'>
<div id='div2'>
<button class='btn'> button 2</button>
<button class='btn'>button 3</button>
<button class='btn'>button 1</button>
</div>
</div>
CSS
#div1 {
position:relative;
background-color:green;
height:400px
}
#div2 {
background-color:blue;
height:200px;
text-align:center;
}
.btn {
position:absolute;
top: 50%;
transform: translateY(-50%)
}
source
share