Questions tagged [flexbox]

CSS module for flexible layouts providing a broad range of options for aligning elements while eliminating the need for floats and tables.

In the flex layout model, the children of a flex container can be laid out in any direction, in any order (independent of source order), and can "flex" their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children can be easily manipulated. Nesting of these boxes (horizontal inside vertical, or vertical inside horizontal) can be used to build layouts in two dimensions.


Flexbox Specification


Modern Flexbox Articles

Articles

Browser Support Information

Canonical Questions & Answers:

21882 questions
303
votes
5 answers

Chrome / Safari not filling 100% height of flex parent

I want to have a vertical menu with a specific height. Each child must fill the height of the parent and have middle-aligned text. The number of children is random, so I have to work with dynamic values. Div .container contains a random number of…
Ricardo Castañeda
  • 5,746
  • 6
  • 28
  • 41
283
votes
11 answers

100% width in React Native Flexbox

I have already read several flexbox tutorial, but I still cannot make this simple task to work. How can I make the red box to 100% width? Code: Welcome to React Natives …
franfran
  • 3,085
  • 2
  • 18
  • 11
276
votes
11 answers

Prevent flex items from overflowing a container

How do I make my flex item (article in this example), which has flex-grow: 1; not to overflow its flex parent/container (main)? In this example article is just text, though it might contains other elements (tables, etc). main, aside, article { …
philfreo
  • 41,941
  • 26
  • 128
  • 141
273
votes
3 answers

How to set a fixed width column with CSS flexbox

I want the red box to be only 25 em wide when it's in the side-by-side view - I'm trying to achieve this by setting the CSS inside this media query: @media all and (min-width: 811px) {...} to: .flexbox .red { width: 25em; } But when I do that,…
Science
  • 2,875
  • 2
  • 12
  • 7
271
votes
2 answers

Position last flex item at the end of container

This question concerns a browser with full css3 support including flexbox. I have a flex container with some items in it. They are all justified to flex-start but I want the last .end item to be justified to flex-end. Is there a good way to do this…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
254
votes
9 answers

My position: sticky element isn't sticky when using flexbox

I was stuck on this for a little bit and thought I'd share this position: sticky + flexbox gotcha: My sticky div was working fine until I switched my view to a flex box container, and suddenly the div wasn't sticky when it was wrapped in a flexbox…
bholtbholt
  • 11,281
  • 6
  • 22
  • 32
252
votes
11 answers

What does flex: 1 mean?

As we all know, the flex property is a shorthand for the flex-grow, flex-shrink, and the flex-basis properties. Its default value is 0 1 auto, which means flex-grow: 0; flex-shrink: 1; flex-basis: auto; but I've noticed, in many places flex: 1 is…
Md Rafee
  • 5,070
  • 3
  • 23
  • 32
240
votes
3 answers

How to stretch children to fill cross-axis?

I have a left-right flexbox: .wrapper { display: flex; flex-direction: row; align-items: stretch; width: 100%; height: 70vh; min-height: 325px; max-height:570px; } .wrapper>.left { background: #fcc; } .wrapper>.right { …
Deborah Cole
  • 2,876
  • 3
  • 19
  • 19
236
votes
7 answers

Why can't
be flex containers?

I tried to style a fieldset element with display: flex and display: inline-flex. However, it didn't work: flex behaved like block, and inline-flex behaved like inline-block. This happens both on Firefox and Chrome, but strangely it works on IE. Is…
Oriol
  • 274,082
  • 63
  • 437
  • 513
233
votes
8 answers

Why does flexbox stretch my image rather than retaining aspect ratio?

Flexbox has this behaviour where it stretches images to their natural height. In other words, if I have a flexbox container with a child image, and I resize the width of that image, the height doesn't resize at all and the image gets…
sjbuysse
  • 3,872
  • 7
  • 25
  • 37
231
votes
5 answers

CSS-only masonry layout

I need to implement a masonry layout. However, for a number of reasons I don't want to use JavaScript to do it. Parameters: All elements have the same width Elements have a height that cannot be calculated server side (an image plus various…
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
228
votes
2 answers

Equal height rows in CSS Grid Layout

I gather that this is impossible to achieve using Flexbox, as each row can only be the minimal height required to fit its elements, but can this be achieved using the newer CSS Grid? To be clear, I want equal height for all elements in a grid across…
Hlsg
  • 3,213
  • 2
  • 12
  • 17
228
votes
9 answers

When flexbox items wrap in column mode, container does not grow its width

I am working on a nested flexbox layout which should work as follows: The outermost level (ul#main) is a horizontal list that must expand to the right when more items are added to it. If it grows too big, there should be a horizontal scroll…
Anders Marzi Tornblad
  • 18,896
  • 9
  • 51
  • 66
219
votes
5 answers

How to specify an element after which to wrap in css flexbox?

I don't think this is part of the flexbox standard yet, but is there maybe a trick to suggest or force wrapping after a certain element? I'd like to respond to different page sizes and wrap a list differently without extra markup, so that rather…
theazureshadow
  • 9,499
  • 5
  • 33
  • 48