Solution 1 :

* {
  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;

Solution 2 :

CSS:

.container {
    display: flex;
    width: 200px;
    height: 200px;
    border: 1px solid red;
    flex-wrap: wrap;
    box-sizing:border-box
}

.container div {
    width: 50%;
    height: 100px;
    border: 1px solid green;
    box-sizing:border-box       
}

.container .box1,
.container .box3{
    text-align: left    
}

.container .box2,
.container .box4{
    text-align: center  
}

HTML:

<div class="container">
    <div class="box1">sample text</div>
    <div class="box2">sample text</div>
    <div class="box3">sample text</div>
    <div class="box4">sample text</div>
</div>

Problem :

I would like to build a “grid”/”table” using flexbox which has 2 rows and 2 columns. In the two items of the left column I want the text to be aligned to the left while in the two items of the right column I want the text to be centered. As easy as it seems to be, I cannot figure out how to achieve this goal using flexbox. I would be very delighted if someone could provide a small example on how to do this.

Comments

Comment posted by dale landry

Please add any code you have attempted to make this work to your question.

Comment posted by PolarBear

Thank you for your answer. To be more precise, in your example I would like to have the green boxes of the left column aligned to the left (touching the left border of the left column) and the green boxes of the right column remain centered. Is this possible?

Comment posted by Kunal Tanwar

just remove the padding-left !!

By