The best way to Flex Grid 2 Columns utilizing CSS


If you need to flex grid 2 columns in CSS you then want three (3) divs.

Step 1 – Set your HTML template

Create some HTML with this structure.

<div class="Guardian">
  <div class="child1">
      <h1>Left</h1>
  </div>
  <div class="child2">
      <h1>RIGHT</h1>
  </div>
</div>

Step 2 – Container Div

Create a Guardian div that makes use of the Flexbox show mannequin.

.Guardian {
  show: flex;
  flex-direction: row;
}

Step 3 – Little one Divs

Create two (2) divs which might be each 50% of the guardian container.

Beneath we set the peak to 100% of the viewport top.

.child1 {
  width: 50%;
  top: 100vh;
  background-color: inexperienced;
}

.child2 {
  width: 50%;
  top: 100vh;
  background-color: purple;
}

Step 4 – Some gotchas to pay attention to

You also needs to set the padding and margin to “ to verify there is no such thing as a overlap.

.physique {
  padding: 0;
  margin: 0;
}

Additionally it is good follow to set the border-box as follows:

box-sizing: border-box;

general method to set these are as follows:

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

Leave a Reply