Is there some way CSS flexbox will remove columns (flex items) when the available real estate is small - similar to the functionality provided by FooTable?
Asked
Active
Viewed 2,730 times
1 Answers
2
The element will tighten up to 0px
if needed. Hiding the content can be handled by using overflow: hidden
, but beware that this may create problems in other scenarios.
Check the following snippet to see the result:
.container {
display: flex;
}
.child1, .child3 {
flex: 1 0 50%;
}
.child2 {
flex: 1;
overflow: hidden;
}
<div class="container">
<div class="child1">child1</div>
<div class="child2">child2</div>
<div class="child3">child3</div>
</div>
Other suggestions:
- Use media queries to hide the content depending on the window size;
- Use media queries to apply the
overflow
property depending on the window size; - If you don't want to hide it, go with
flex-wrap
to spread your flex items into 2+ rows

gustavohenke
- 40,997
- 14
- 121
- 129
-
+1 for the suggestion, but I was hoping to find a solution where child2 is visible sometimes (big container), and not visible at other times (smaller container). – Upperstage Jul 29 '15 at 18:24
-
thank you for sticking with this, but I never see child2. Even when I click the Full page button, child2 is always hidden. I am using Chrome. – Upperstage Jul 29 '15 at 19:05
-
@Upperstage right, because the other elements are occupying the rest of the container. If you give enough room for `.child2` to be shown, it'll be shown. If you need some more specific control over this flex item, you should go with JS or media queries. – gustavohenke Jul 29 '15 at 20:57
-
"If you give enough room for .child2 to be shown, it'll be shown" - sorry, but I tried Chrome and Firefox (doesn't work in IE), but I never see child2. – Upperstage Jul 30 '15 at 13:40
-
Yes, because the other flex items have 50% width :) – gustavohenke Jul 30 '15 at 18:30
-
That misses the point of my question. I want to SEE child2 when real estate is available. – Upperstage Aug 05 '15 at 19:59