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
483
votes
20 answers

Vertical Align Center in Bootstrap 4

I am trying to center my Container in the middle of the page using Bootstrap 4. I have been unsuccessful thus far. Any help would be appreciated. I have built it at Codepen.io so you guys can play with it and let me know what works as I am about out…
canaan seaton
  • 6,688
  • 4
  • 17
  • 25
482
votes
11 answers

How to make Flexbox items the same size

I want to use Flexbox that has some number of items that are all the same width. I've noticed that Flexbox distributes the space around evenly, rather than the space itself. For example: .header { display: flex; } .item { flex-grow: 1; …
Chet
  • 18,421
  • 15
  • 69
  • 113
476
votes
24 answers

Bootstrap align navbar items to the right

How do I align a navbar item to right? I want to have the login and register to the right. But everything I try does not seem to work. This is what I have tried so far:
around the
469
votes
12 answers

Can't scroll to top of flex item that is overflowing container

In attempting to make a useful modal using flexbox, I found what seems to be a browser issue and am wondering if there is a known fix or workaround -- or ideas on how to resolve it. The thing I'm trying to solve has two aspects. First, getting the…
jejacks0n
  • 5,552
  • 3
  • 18
  • 12
412
votes
6 answers

How to justify a single flexbox item (override justify-content)

You can override align-items with align-self for a flex item. I am looking for a way to override justify-content for a flex item. If you had a flexbox container with justify-content:flex-end, but you want the first item to be justify-content:…
Mahks
  • 6,441
  • 6
  • 28
  • 31
404
votes
5 answers

How can I align one item right with flexbox?

https://jsfiddle.net/vhem8scs/ Is it possible to have two items align left and one item align right with flexbox? The link shows it more clearly. The last example is what I want to achieve. In flexbox I have one block of code. With float I have four…
Jens Törnell
  • 23,180
  • 45
  • 124
  • 206
376
votes
9 answers

How to specify line breaks in a multi-line flexbox layout?

Is there a way to make a line break in multiple line flexbox? For example to break after each 3rd item in this CodePen. .container { background: tomato; display: flex; flex-flow: row wrap; align-content: space-between; …
Artem Svirskyi
  • 7,305
  • 7
  • 31
  • 43
367
votes
4 answers

How can I have two fixed width columns with one flexible column in the center?

I'm trying to set up a flexbox layout with three columns where the left and right columns have a fixed width, and the center column flexes to fill the available space. Despite setting up dimensions for the columns, they still seem to shrink as the…
mheavers
  • 29,530
  • 58
  • 194
  • 315
354
votes
11 answers

Center one and right/left align other flexbox element

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
  • 3,618
  • 3
  • 12
  • 14
350
votes
6 answers

What are the differences between flex-basis and width?

There have been questions and articles about this, but nothing conclusive as far as I can tell. The best summary I could find is flex-basis allows you to specify the initial/starting size of the element, before anything else is computed. It can…
jpeltoniemi
  • 5,320
  • 7
  • 24
  • 34
348
votes
6 answers

Fill remaining vertical space with CSS using display:flex

In a 3-row layout: the top row should be sized according to its contents the bottom row should have a fixed height in pixels the middle row should expand to fill the container The problem is that as the main content expands, it squishes the header…
Zilk
  • 8,917
  • 7
  • 36
  • 44
341
votes
11 answers

Scrolling a flexbox with overflowing content

Here's the code I'm using to achieve the above layout: .header { height: 50px; } .body { position: absolute; top: 50px; right: 0; bottom: 0; left: 0; display: flex; } .sidebar { width: 140px; } .main { flex:…
Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
339
votes
12 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
  • 16,906
  • 20
  • 84
  • 117
334
votes
22 answers

ReactNative: how to center text?

How to center Text in ReactNative both in horizontal and vertical? I have an example application in rnplay.org where justifyContent="center" and alignItems="center" is not working: https://rnplay.org/apps/AoxNKQ The text should being centered. And…
itinance
  • 11,711
  • 7
  • 58
  • 98
304
votes
23 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
  • 20,996
  • 12
  • 82
  • 123