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
144
votes
2 answers

Force flex item to span full row width

I'm trying to retain the first 2 child elements on the same row while the third element is in its own below at full width, all while using flex. I'm particularly interested in using the flex-grow and flex-shrink properties on the first 2 elements…
MPaul
  • 2,553
  • 3
  • 20
  • 34
140
votes
2 answers

margin-top only when the flex item is wrapped

I have a flex container with two flex items. I want to set a margin-top on the second one, but only when it's wrapped and not at the first flex line. If possible, I want to avoid using media queries. I thought margin-bottom on the first element…
Manuel Di Iorio
  • 3,631
  • 5
  • 29
  • 31
137
votes
5 answers

Flexbox: how to get divs to fill up 100% of the container width without wrapping?

I'm in the process of updating an old inline-block-based grid model I have to a newer Flexbox one I created. Everything has worked fine, apart from one little snag, which has become a bit of a dealbreaker: I have a bunch of CSS-controlled sliders;…
indextwo
  • 5,535
  • 5
  • 48
  • 63
133
votes
6 answers

Prevent a flex items height from expanding to match other flex items

I have two elements inside a container, which are being side-by-side by using flex box. On the second element (.flexbox-2), I am setting it's height in the CSS. However, then the first element (.flexbox-1) will match the height of .flexbox-2. How…
Tom Oakley
  • 6,065
  • 11
  • 44
  • 73
131
votes
3 answers

Arrange 2 items per row using flexbox

Imagine I have following markup
and style .item { width: 100% } and due to certain reasons I can't…
PranavPinarayi
  • 3,037
  • 5
  • 21
  • 32
131
votes
11 answers

Why isn't my justify-content property working?

I'm trying to add some space between the sidebar and content area of the template by applying the "justify-content" property to the parent div, but it's not adding that space between the sidebar and content area. I'm not sure what it is that I'm…
VEDA0095
  • 1,575
  • 4
  • 11
  • 13
129
votes
4 answers

Does 'position: absolute' conflict with Flexbox?

I want to make a div stick on the top of the screen without any influence to other elements, and its child element in the center. .parent { display: flex; justify-content: center; position: absolute; }
Stanley Luo
  • 3,689
  • 5
  • 34
  • 64
129
votes
5 answers

Flexbox and Internet Explorer 11 (display:flex in ?)

I am planning to move away from "floaty" layouts and use CSS flexbox for future projects. I was delighted to see that all major browsers in their current versions seem to support (in one way or another) flexbox. I headed over to "Solved by Flexbox"…
Kodekan
  • 1,601
  • 2
  • 13
  • 20
126
votes
9 answers

Maintain image aspect ratio when changing height

Using the CSS flex box model, how can I force an image to maintain its aspect ratio? JS Fiddle: http://jsfiddle.net/xLc2Le0k/2/ Notice that the images stretch or shrink in order to fill the width of the container. That's fine, but can we also have…
coderMe
  • 2,099
  • 3
  • 18
  • 20
123
votes
10 answers

Flexbox Not Centering Vertically in IE

I have a simple web page with some Lipsum content that is centered on the page. The page works fine in Chrome and Firefox. If I reduce the size of the window, the content fills the window until it can't and then adds a scroll bar and fills content…
Dragonseer
  • 2,874
  • 7
  • 29
  • 42
120
votes
7 answers

Center the content inside a column in Bootstrap

I Need help to fix the problem, I need to center the content inside the column in bootstrap4, please find my code below
Praveen Kumar
  • 1,301
  • 2
  • 9
  • 4
118
votes
4 answers

How can I show three columns per row?

I have been trying to show three columns per row. Is it possible using flexbox? My current CSS is something like this: .mainDiv { display: flex; margin-left: 221px; margin-top: 43px; } This code puts all content in a single row. I want…
maxspan
  • 13,326
  • 15
  • 75
  • 104
114
votes
3 answers

CSS3 Flexbox: display: box vs. flexbox vs. flex

Yesterday I got a website in the school which uses the CSS 3 flexbox statement. I never used that before. So I googled it a bit and found a lot of different styles of the flexbox statements. Some guys write display: box;, some use display:…
user1722486
113
votes
4 answers

First-child full-width in Flexbox

How can I set the first-child of flexbox in full-width and all of the other childs set to flex:1(for split space)? Like this:
Dark star
  • 5,192
  • 9
  • 35
  • 54
113
votes
5 answers

How do I set a flex-container to be the width of its flex-items?

I have a flex container with justify-content: flex-start. There ends up being overflow on the right side due to the flex items taking less space than the size of the container. Aside from setting an explicit width on the flex-container, is there a…
BOverflow
  • 1,283
  • 2
  • 11
  • 11