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
1435
votes
40 answers

How do I set distance between flexbox items?

To set the minimal distance between flexbox items I'm using margin: 0 5px on .item and margin: 0 -5px on container. This seems like a hack. Is there another property or method intended to accomplish this goal? #box { display: flex; width:…
Sasha Koss
  • 15,129
  • 4
  • 20
  • 27
1273
votes
41 answers

How to remove the space between inline/inline-block elements?

There will be a 4 pixel wide space between these span elements: span { display: inline-block; width: 100px; background-color: palevioletred; }

Foo Bar

Fiddle Demo I understand that I could get rid…
Šime Vidas
  • 182,163
  • 62
  • 281
  • 385
1065
votes
6 answers

In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?

Consider the main axis and cross axis of a flex container: Source: W3C To align flex items along the main axis there is one property: justify-content To align flex items along the cross axis there are three…
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
951
votes
14 answers

How to Right-align flex item?

Is there a more flexbox-ish way to right-align "Contact" than to use position: absolute? .main { display: flex; } .a, .b, .c { background: #efefef; border: 1px solid #999; } .b { flex: 1; text-align: center; } .c { position:…
Mark Boulder
  • 13,577
  • 12
  • 48
  • 78
944
votes
14 answers

Flexbox: center horizontally and vertically

How to center div horizontally, and vertically within the container using flexbox. In below example, I want each number below each other (in rows), which are centered horizontally. .flex-container { padding: 0; margin: 0; list-style: none; …
bsr
  • 57,282
  • 86
  • 216
  • 316
848
votes
14 answers

How can I make Flexbox children 100% height of their parent?

I'm trying to fill the vertical space of a flex item inside a Flexbox. .container { height: 200px; width: 500px; display: flex; flex-direction: row; } .flex-1 { width: 100px; background-color: blue; } .flex-2 { position:…
Raz
  • 8,981
  • 4
  • 19
  • 18
695
votes
15 answers

What's the difference between align-content and align-items?

What is the difference between align-items and align-content?
Dinh
  • 7,081
  • 3
  • 13
  • 3
660
votes
10 answers

Align an element to bottom with flexbox

I have a div with some children:

heading 1

heading 2

Some more or less text

Click me
and I want the following layout: ------------------- |heading 1 …
supersize
  • 13,764
  • 18
  • 74
  • 133
629
votes
13 answers

How to vertically align text inside a flexbox?

I would like to use flexbox to vertically align some content inside an
  • but not having great success. I've checked online and many of the tutorials actually use a wrapper div which gets the align-items:center from the flex settings on the…
  • styler
    • 15,779
    • 23
    • 81
    • 135
    560
    votes
    35 answers

    Flex-box: Align last row to grid

    I have a simple flex-box layout with a container like: .grid { display: flex; flex-flow: row wrap; justify-content: space-between; } Now I want the items in the last row to be aligned with the other. justify-content: space-between; should be…
    Thorben Croisé
    • 12,407
    • 8
    • 39
    • 50
    547
    votes
    7 answers

    Why don't flex items shrink past content size?

    I have 4 flexbox columns and everything works fine, but when I add some text to a column and set it to a big font size, it is making the column wider than it should be due to the flex property. I tried to use word-break: break-word and it helped,…
    tomas657
    • 5,579
    • 4
    • 16
    • 15
    547
    votes
    10 answers

    What's the difference between display:inline-flex and display:flex?

    I am trying to vertically align elements within an ID wrapper. I gave the property display:inline-flex; to this ID as the ID wrapper is the flex container. But there is no difference in presentation. I expected that everything in the wrapper ID…
    astridx
    • 6,581
    • 4
    • 17
    • 35
    533
    votes
    5 answers

    Flexbox not giving equal width to elements

    Attempting a flexbox nav that has up to 5 items and as little as 3, but it's not dividing the width equally between all the elements. Fiddle The tutorial I'm modeling this after is…
    itsclarke
    • 8,622
    • 6
    • 33
    • 50
    507
    votes
    3 answers

    Fill the remaining height or width in a flex container

    I have 2 divs side-by-side in a flexbox. The right hand one should always be the same width, and I want the left hand one to just grab the remaining space. But it won't unless I specifically set its width. So at the moment, it's set to 96% which…
    Adam Benson
    • 7,480
    • 4
    • 22
    • 45
    495
    votes
    10 answers

    Flexbox: 4 items per row

    I'm using a flex box to display 8 items that will dynamically resize with my page. How do I force it to split the items into two rows? (4 per row)? Here is a relevant snip: (Or if you prefer jsfiddle -…
    V Maharajh
    • 9,013
    • 5
    • 30
    • 31
    1
    2 3
    99 100