* {
margin: 0;
padding: 0;
outline: 0;
box-sizing: border-box;
}
body {
height: 100vh;
display: grid;
place-items: center;
}
.flex {
display: flex;
}
.container {
position: relative;
width: 350px;
height: 350px;
border: 1px solid red;
}
.column {
position: relative;
width: 100%;
height: 100%;
padding: 2rem;
display: flex;
flex-direction: column;
background-color: pink;
}
.column:nth-child(2) {
background-color: coral;
}
.column:nth-child(2) .box {
text-align: center;
/* if you also want to align text vertically center */
/* display: grid;
place-items: center; */
}
.column .box {
width: 100%;
height: 100%;
background-color: lightgreen;
}
.column .box:not(:first-of-type) {
margin-top: 2rem;
}
<div class="container flex">
<div class="column">
<div class="box">
aligned left
</div>
<div class="box">
aligned left
</div>
</div>
<div class="column">
<div class="box">
aligned center
</div>
<div class="box">
aligned center
</div>
</div>
</div>
If you also want to align text vertically center add the below mentioned code inside .box
.
/* grid method */
display: grid;
place-items: center;
/* flex method */
display: flex;
align-items: center;
justify-content: center;