Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grid area won't move into grid rows with percentage values

Tags:

html

css

css-grid

I can get the div to move to the correct column but not the correct row.

This will display the blue rectangle in the correct column, but for whatever reason it isn't moving in to the row I need it to. Thank you all for your help.

body {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 10% 80% 10%;
}

#navigation {
  grid-column: 2/2;
  grid-row: 2/2;
  height: 400px;
  width: 100%;
  background-color: blue;
}
<div id="navigation"></div>
<div id="menunBar"></div>
<div id="mainContent"></div>
like image 753
Matt Comeaux Avatar asked Sep 01 '25 21:09

Matt Comeaux


1 Answers

You're using percentages to set the row heights. That means that a parent reference is required.

Set a height on the grid container.

body {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 10% 80% 10%;
  height: 100vh; /* new */
}

#navigation {
  grid-column: 2/3; /* error correction */
  grid-row: 2/3;
  background-color: blue;
}

body {
  margin: 0;
}
<div id="navigation"></div>
<div id="menunBar"></div>
<div id="mainContent"></div>

More details:

  • Why is percentage height not working on my div?
  • How to make a div 100% height of the browser window?
  • What's the difference between grid-column value 1/1 and 1/2?
like image 58
Michael Benjamin Avatar answered Sep 03 '25 15:09

Michael Benjamin