Skip to content

Instantly share code, notes, and snippets.

@mrmartineau
Last active December 26, 2020 17:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mrmartineau/780c7eece3868fd2990fb53807de330f to your computer and use it in GitHub Desktop.
Save mrmartineau/780c7eece3868fd2990fb53807de330f to your computer and use it in GitHub Desktop.
CSS grid snippets

Basic grid

.grid {
  display: grid;
  grid-gap: 30px;
  grid-template-columns: repeat(auto-fill, 112px);
  /* or this */
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
}

Feature detects

// To select modern Grid browsers and IE 11
@supports (display: grid) {
  grid-gap: 20px;
}

// Else
@supports not (display: grid) {
  li {
    padding: 10px;
  }
}

/* Edge 16 and higher */
@supports (display: -ms-grid) and (display: grid) {
  div {
    width: auto;
  }
}

/* Edge 15 and lower */
@supports (display: -ms-grid) and (not (display: grid)) {
  div {
    margin: 0
  }
}

// To select only Grid browsers without IE 11
@supports (grid-gap: 0) {
  grid-gap: 20px;
}

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment