Skip to content

Instantly share code, notes, and snippets.

@Knogobert
Last active July 3, 2019 13:39
Show Gist options
  • Save Knogobert/ac11478943d2c6211c0adba006630cd4 to your computer and use it in GitHub Desktop.
Save Knogobert/ac11478943d2c6211c0adba006630cd4 to your computer and use it in GitHub Desktop.
CSS — Flexbox Albatross method for context aware media queries
<main class="parent">
<div class="child"></div>
<div class="gutter"></div>
<div class="child"></div>
</main>
$gutter: 1.5rem;
$children-min-width: 40rem; // Break into fullsize columns if children together are smaller than this
.parent {
display: flex;
flex-wrap: wrap;
.child {
flex-grow: 1;
flex-basis: calc((#{$children-min-width} - 100%) * 999); // The flexbox albatross
}
}
/* If more than 4 children, go fullsize */
.parent > :nth-last-child(n+5),
.parent > :nth-last-child(n+5) ~ * {
flex-basis: 100%;
}
.gutter {
flex: 0 1 $gutter;
min-height: $gutter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment