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:

17648 questions
225
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
  • 225,583
  • 46
  • 371
  • 457
218
votes
9 answers

Keep the middle item centered when side items have different widths

Imagine the following layout, where the dots represent the space between the boxes: [Left box]......[Center box]......[Right box] When I remove the right box, I like the center box to still be in the center, like so: [Left box]......[Center…
Mark
  • 12,916
  • 16
  • 70
  • 94
208
votes
10 answers

Right or left align one flex item, while keeping the others centered

I would like to have A B and C aligned in the middle. How can I get D to go completely to the right? BEFORE: AFTER: ul { padding: 0; margin: 0; display: flex; flex-direction: row; justify-content: center; align-items:…
hazyred
  • 2,158
  • 2
  • 9
  • 14
194
votes
6 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
  • 2,966
  • 5
  • 15
  • 27
192
votes
13 answers

Text in a flex container doesn't wrap in IE11

Consider the following snippet: .parent { display: flex; flex-direction: column; width: 400px; border: 1px solid red; align-items: center; } .child { border: 1px solid blue; }
Misha Moroshko
  • 148,413
  • 200
  • 467
  • 700
189
votes
16 answers

React native text going off my screen, refusing to wrap. What to do?

The following code can be found in this live example I've got the following react native element: 'use strict'; var React = require('react-native'); var { AppRegistry, StyleSheet, Text, View, } = React; var SampleApp = React.createClass({ …
SudoPlz
  • 14,037
  • 8
  • 67
  • 100
185
votes
7 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
  • 17,122
  • 9
  • 50
  • 62
183
votes
2 answers

How to set a fixed width column with CSS flexbox

CodePen: http://codepen.io/anon/pen/RPNpaP. 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…
Science
  • 1,975
  • 2
  • 9
  • 7
176
votes
1 answer

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; }
Left
Deborah Cole
  • 2,226
  • 3
  • 15
  • 19
174
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
  • 8,053
  • 5
  • 31
  • 46
161
votes
3 answers

CSS-only masonry layout

I need to implement a fairly run-off-the-mill 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…
Pekka
  • 418,526
  • 129
  • 929
  • 1,058
161
votes
3 answers

Flexbox vs Twitter Bootstrap (or similar framework)

I have recently discovered Flexbox when I was looking for a solution to make divs the same hight, depending on the highest one. I have read the following page on CSS-tricks.com and it convinced me that flexbox is a very powerful module to learn and…
Rvervuurt
  • 7,171
  • 7
  • 35
  • 53
159
votes
5 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
  • 3,390
  • 2
  • 15
  • 25
153
votes
5 answers

How to align flexbox columns left and right?

With typical CSS I could float one of two columns left and another right with some gutter space in-between. How would I do that with flexbox? http://jsfiddle.net/1sp9jd32/ #container { width: 500px; border: solid 1px #000; display:…
archytect
  • 2,975
  • 4
  • 18
  • 27