UPDATE: So I was able to make this work with Flexbox Codepen However, as some in the community point out, the caveats (such as fixed heights) prove that CSS grid is the best case for layout.
I'm trying to rely on Flexbox row wrapping for as much layout as possible. I keep running into the scenario where I want to stack two or more elements on top of each other (similar to floating) but do not want to add markup which would defeat the purpose here.
I cannot find any examples of this anywhere, perhaps its impossible?
I've created a CodePen to show how I'm trying to stack two elements and then in another row stack 3 items.
body {
display: flex;
flex-wrap: wrap;
}
.full-width {
flex: 100%;
}
.fifty {
flex: 0 0 50%;
}
.one-third {
flex: 0 0 33%;
}
.twnty-five {
flex: 0 0 25%;
}
div.one-third:nth-child(6),
div.one-third:nth-child(7) {
// margin: auto;
flex: 0 0 33%;
max-height: 50px;
height: 45px;
min-height: 45px;
}
div.twnty-five:nth-child(11),
div.twnty-five:nth-child(12),
div.twnty-five:nth-child(13) {
// margin-left:auto;
flex: 0 0 25%;
height: 25px;
min-height: 25px;
}
div {
display: flex;
min-height: 100px;
align-items: center;
justify-content: center;
text-align: center;
border: 1px solid #DFDFDF;
box-sizing: border-box;
}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
<div class="full-width">full-width</div>
<div class="fifty">fifty</div>
<div class="fifty">fifty</div>
<div class="one-third">one-third</div>
<div class="one-third">one-third</div>
<div class="one-third">one-third stack top</div>
<div class="one-third">one-third stack bottom</div>
<div class="twnty-five">twnty-five</div>
<div class="twnty-five">twnty-five</div>
<div class="twnty-five">twnty-five</div>
<div class="twnty-five">stack top</div>
<div class="twnty-five">stack middle</div>
<div class="twnty-five">stack bottom</div>
<!--
Copyright (c) 2018 by Ben Racicot (https://codepen.io/BRacicot/pen/bxGrYP)
Fork of an original work by Ben Racicot (https://codepen.io/BRacicot/pen/ZjrZQw)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->