Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Css3 Grid Layout Not Working Even When I Copy an Example from w3.org

Would appreciate any help trying to get css3/html grid layout to work. I have tried the below code in IE, chrome, and Edge, and can't get it to work. Maybe there is something I have overlooked.

#grid {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 1fr auto;
}
#title {
  grid-column: 1;
  grid-row: 1;
}
#score {
  grid-column: 1;
  grid-row: 3;
}
#stats {
  grid-column: 1;
  grid-row: 2;
  align-self: start;
}
#board {
  grid-column: 2;
  grid-row: 1 / span 2;
}
#controls {
  grid-column: 2;
  grid-row: 3;
  justify-self: center;
}
<div id="grid">
  <div id="title">Game Title</div>
  <div id="score">Score</div>
  <div id="stats">Stats</div>
  <div id="board">Board</div>
  <div id="controls">Controls</div>
</div>
like image 603
W. Wuffley Avatar asked Jul 05 '16 19:07

W. Wuffley


People also ask

Why is grid template columns not working CSS?

The problem is that you are applying the grid-template-columns property to grid items. This is a grid container property. It will be ignored on grid items (unless they are also grid containers). Instead use the grid-column and grid-row properties, which apply to grid items.

How do I make my grid template responsive?

Building a Responsive Grid-View First ensure that all HTML elements have the box-sizing property set to border-box . This makes sure that the padding and border are included in the total width and height of the elements. Read more about the box-sizing property in our CSS Box Sizing chapter.

How do I turn on grid in CSS?

You can turn on the grid button located in the div which has display: grid declared. All you have to do is go to your browser's developer tools (mine is Microsoft Edge which is based on Chromium). You will see a button like this. And then you can code and test as you wish.


1 Answers

The Grid implementation(s) are not widely (or hardly at all) available in any browser as of July 5, 2016.

You can enable it in:

  • Firefox; with the setting - layout.css.grid.enabled
  • Webkit nightly; with the prefix - -webkit-
  • IE/Edge; with the prefix - -ms-
  • Chrome; with the experimental Web Platform features flag in chrome://flags

Note that the Firefox/Chrome options only enable this for you, and there's no way to force a user to enable these settings, so this would be for experimentation purposes only.

like image 59
rockerest Avatar answered Sep 20 '22 17:09

rockerest