Skip to content

Instantly share code, notes, and snippets.

@mherchel
Last active May 25, 2019 19:13
Show Gist options
  • Save mherchel/1c2b5c919e084af378d8fce635925182 to your computer and use it in GitHub Desktop.
Save mherchel/1c2b5c919e084af378d8fce635925182 to your computer and use it in GitHub Desktop.
/// Wraps ruleset within media and @supports queries that only affect browsers that don't support grid.
@mixin no-grid {
@media (-ms-high-contrast: none), (-ms-high-contrast: active) {
@content;
}
@supports not (display: grid) {
@content;
}
}
// Usage
.selector {
@include grid-container; // Assume this holds the grid content rules.
@include no-grid {
// Insert flexbox fallback code
}
}
// Will compile down to the following:
.selector {
display: grid;
grid-template-rows: repeat(12, 1fr);
grid-column-gap: 30px;
/* the -ms-high-contrast mq only affects IE10/IE11 */
@media (-ms-high-contrast: none), (-ms-high-contrast: active) {
/* Flexbox fallback code */
}
@supports not (display: grid) {
/* Flexbox fallback code */
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment