Skip to content

Instantly share code, notes, and snippets.

@BonfaceKilz
Last active March 9, 2018 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BonfaceKilz/af8be07f7fa1cef90d47b5fcf4301907 to your computer and use it in GitHub Desktop.
Save BonfaceKilz/af8be07f7fa1cef90d47b5fcf4301907 to your computer and use it in GitHub Desktop.
A quick primer on css grids

A handy of using css grids:

.grid-container {
  display: grid;
  grid-template-columns: 100px 100px 100px;
  grid-template-rows: 50px 50px;
}

// Alternatively
.grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  // or using fraction units
  // grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 50px);
  grid-gap: 3px;
}

// Using grid shorthand
.grid-container {
  display: grid;
  // row then column
  grid-template: repeat(2, 50px) / repeat(3, 1fr);
  grid-template: repeat
}

Here's an alternative way of displaying the content using gfid-area:

.grid-container {
  display: grid;
  grid-gap: 3px;
  grid-template-columns: repeat(12, 1fr);
  grid- template-rows: 40px auto 40px;
  // use dots for blank areas
  grid-template-areas:
    "h h h h h h h h h h h h"
    "m c c c c c c c c c c c"
    "f f f f f f f f f f f f";    
}

.header {
  grid-area; h;
};

.menu {
  grid-area: m;
};

.footer {
  grid-area: f;
};

Here's how you use autofit and minmax:

.container {
  display: grid;
  grid-template-columns: repeat(auto, minmax(100px, 1fr);
  grid-auto-row: 100px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment