Struggling to achieve vertical alignment in CSS, I tried the following code snippet:
.base{
background-color:green;
width:200px;
height:200px;
overflow:auto;
position:relative;
}
.vert-align{
padding-top:50%;
height:50%;
}
<!-- Used the following div structure. -->
<div class="base">
<div class="vert-align">
Content Here
</div>
</div>
Although it worked initially, I encountered an issue when resizing the base div. The vertical alignment would suddenly snap due to the padding being calculated as a percentage of the width instead of the height of the parent container. Is there a way to set the padding and/or margin as a percentage of the height without JavaScript?