Last active
July 3, 2019 13:39
-
-
Save Knogobert/ac11478943d2c6211c0adba006630cd4 to your computer and use it in GitHub Desktop.
CSS — Flexbox Albatross method for context aware media queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<main class="parent"> | |
<div class="child"></div> | |
<div class="gutter"></div> | |
<div class="child"></div> | |
</main> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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
Source: http://www.heydonworks.com/article/the-flexbox-holy-albatross
&&
https://css-tricks.com/putting-the-flexbox-albatross-to-real-use/