Created
March 24, 2022 19:09
-
-
Save Snugug/9cb053788ae7306ee78690fe3519544f to your computer and use it in GitHub Desktop.
Flexbox 1 column to 2 columns, no 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
<div class="container"> | |
<div class="left-item">Left</div> | |
<div class="right-item">Right</div> | |
</div> |
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
* { | |
box-sizing: border-box; | |
} | |
.container { | |
display: flex; | |
// Wrap if everything can't fit in one line | |
flex-wrap: wrap; | |
border: 1px solid black; | |
} | |
// left-item and right-item's total width (flex-basis as width for box model) should be <= 100% | |
.left-item { | |
// Grow, don't shrink, aim to be 30% of the available space | |
// flex-grow, flex-shrink, flex-basis | |
flex: 1 0 30%; | |
// Be at least 300px wide. Key for the transition to happen! | |
min-width: 300px; | |
background: yellow; | |
border: 1px solid black; | |
} | |
.right-item { | |
// Grow, shrink, and aim to be at least 70% of the available space | |
flex: 1 1 70%; | |
background: orange; | |
border: 1px solid black; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment