I’d like to position Items "inline" behind Text. And when they wrap, they should be wrapped directly under Text. I don’t want to change HTML markup, since my actual use case is more complicated and won’t allow that. Is something like that possible?
.outer-container {
background-color: lightgray;
display: flex;
flex-wrap: wrap;
}
.item-container {
display: inline-flex;
flex-wrap: wrap;
}
.text {
border: 1px solid black;
}
.item {
min-width: 200px;
border: 1px solid black;
}
<div class="outer-container">
<div class="text">Text</div>
<div class="item-container">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
<div class="item">Item 4</div>
<div class="item">Item 5</div>
</div>
</div>
I tried using inline-flex, but it didn’t work.
Current :
Wanted result:
CodeSandBox: https://codesandbox.io/s/boring-hertz-idh1fb?file=/index.html
4
Answers
The thing is that the 2 children of
outer-container
are divided bydisplay: flex;
where.text
is getting full height 😀 if you get rid of thewrap
property :(.The only solution is to insert
.text
item into the same container where you givedisplay: flex;
property as this:Try
display: contents
Use display contents rather than flex on the item container. Its children are then treated by the flex in the outer container as though they were directly in it.