Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CSS Grid 2 cols and half height

Im trying to get my CSS grid into 2 columns with the same parent height but each smaller box half the height of the main box. See attached image. However I can’t quite get the right layout and need some help. Please see my code so far.

enter image description here

.item1 { grid-area: header; }
.item2 { grid-area: menu; height:200px;}
.item3 { grid-area: main; height:100px;}
.item4 { grid-area: right; height:100px;}
.item5 { grid-area: footer; height:200px;}

.grid-container {
  display: grid;
  grid-template-areas:
    'header header'
    'menu right'
    'main footer';
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

.grid-container > div {
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  padding: 20px 0;
  font-size: 30px;
}
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<h1>Grid Layout</h1>

<div class="grid-container">
  <div class="item1">Header</div>
  <div class="item2">Menu</div>
  <div class="item3">Main</div>  
  <div class="item4">Right</div>
  <div class="item5">Footer</div>
</div>

</body>
</html>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is a missing row in the grid template areas definition.

.item1 {
  grid-area: header;
}

.item2 {
  grid-area: menu;
  height: 200px;
}

.item3 {
  grid-area: main;
  height: 100px;
}

.item4 {
  grid-area: right;
  height: 100px;
}

.item5 {
  grid-area: footer;
  height: 200px;
}

.grid-container {
  display: grid;
  grid-template-areas: 'header header' 'menu right' 'menu footer' 'main footer';
  gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

.grid-container>div {
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  padding: 20px 0;
  font-size: 30px;
}
<!DOCTYPE html>
<html>

<head>

</head>

<body>

  <h1>Grid Layout</h1>

  <div class="grid-container">
    <div class="item1">Header</div>
    <div class="item2">Menu</div>
    <div class="item3">Main</div>
    <div class="item4">Right</div>
    <div class="item5">Footer</div>
  </div>

</body>

</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading