Sunday, March 19, 2023
HomeSoftware EngineeringHow one can Flex Grid 2 Columns utilizing CSS

How one can Flex Grid 2 Columns utilizing CSS


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

Step 1 – Set your HTML template

Create some HTML with this format.

<div class="Father or mother">
  <div class="child1">
      <h1>Left</h1>
  </div>
  <div class="child2">
      <h1>RIGHT</h1>
  </div>
</div>

Step 2 – Container Div

Create a Father or mother div that makes use of the Flexbox show mannequin.

.Father or mother {
  show: flex;
  flex-direction: row;
}

Step 3 – Youngster Divs

Create two (2) divs which are each 50% of the mum or dad container.

Under we set the peak to 100% of the viewport peak.

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

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

Step 4 – Some gotchas to concentrate on

You also needs to set the padding and margin to “ to verify there isn’t a overlap.

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

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

box-sizing: border-box;

A great general approach to set these are as follows:

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments