What Are Allowed Values of the 'Display' Property for a Flex-Item? (Layout of Flex-Item's Children Is Irrelevant)

What are allowed values of the `display` property for a flex-item? (layout of flex-item’s children is irrelevant)

The only condition for being a flex item is being an in-flow child of a flex container.

Note this means a contiguous run of text can be wrapped inside an anonymous flex item which do not correspond to any element, and an element child of a flex container might not be a flex item if any of the following

  • It is absolutely positioned

    an absolutely-positioned child of a flex container does not participate in flex layout.

  • It has display: contents

    The element itself does not generate any boxes, but its children and
    pseudo-elements still generate boxes as normal. For the purposes of
    box generation and layout, the element must be treated as if it had
    been replaced with its children and pseudo-elements in the document
    tree.

    Its children will become the flex items instead (unless something from this list applies to them).

  • It has display: none

    The element and its descendants generates no boxes.

  • It has box-suppress: discard

    The element generates no boxes at all.

  • It has box-suppress: hide

    The element generates boxes as normal, but those boxes do not
    participate in layout in any way, and must not be displayed.

  • Previously, if a child of a flex container had a display value that generated an anonymous parent, that parent became the flex item instead of the child. This changed and now the child becomes the flex item, and no parent is generated.

Apart from that, yes, the display value should not prevent an element from being a flex item.

Be aware that flex items are blockified, so for example inline-block becomes block, inline-table becomes table, inline-flex becomes flex, etc.

This means that, whatever the specified outer display role, the flex item will always be block-level.

Basically, the display property, when used on a flex item, is only useful to set its inner display layout model, e.g. that you want the flex item to be a flex container for its contents.

A flex item establishes a new formatting context for its
contents. The type of this formatting context is determined by its
display value, as usual. However, flex items themselves are
flex-level boxes, not block-level boxes: they participate in their container’s flex formatting context, not in a block formatting
context.

(The terminology differs a bit, the Display spec says a flex item is block-level in the sense of its outer display role, the Flexbox spec says it's not block-level in the sense that the formatting context in which it participates is not a block one)

Making a child of a flex container NOT a flex item

Updated based on a question edit

No, there is no property that can be set, to make a flex container child stop being a flex item.

What can be done though, is to not use any flex properties on one, and by that make it behave as a block or inline-block element.

E.g., combined with flex-wrap: wrap enabling items to wrap, giving the third item flex: none will make it behave as an inline block, giving it width: 100% it will behave as a block (as shown below).

When it comes to flex container properties, some can be overridden on the item, like align-items / align-self, some cannot, like justify-content.

To mimic justify-content in your given code sample, auto margins could be used, and with that, together with a trick using the order property and a pseudo element, one could make the third behave like an inline block:

.flex{  display: flex;  flex-wrap: wrap;  align-content: flex-start;  width: 400px;  height: 400px;  background: #ccc;}
.child{ width: 100px; height: 100px; background: red; margin: 20px;}
.child.one{ margin-left: auto;}.child.two{ margin-right: auto;}
.flex::after{ content: ''; width: 100%; order: 1;}.child.three{ background: blue; order: 2;}
Is there any way to make child three not behave as a flex child?  <div class="flex">    <div class="child one"></div>    <div class="child two"></div>    <div class="child three"></div>  </div>

Flex item exceeds its container

To achieve expected result, specify the width for the .flexible class as well

.flexible { 
flex: 1 0 auto;
width: 200px;
background-color: blue;
word-wrap: break-word;
}

http://codepen.io/nagasai/pen/LkJzLz

display: flex shows underlined icons

<a> tags have text-decoration:underline by default, thats why the line is coming below.

Apply text-decoration: none to your anchor tags .nav a

Stack Snippet

.nav {  width: 60px;  height: 100vh;  top: 100px;  min-height: 100vh;  background-color: #cccccc;  position: fixed;  z-index: 999;  opacity: .4;  border-right: 1px solid black;  display: flex;  flex-direction: column;}
.nav a { width: 100%; height: 60px; display: flex; justify-content: center; align-items: center; border: none; text-decoration: none;}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"><div class="nav">  <a href=""><i class="material-icons">home</i></a>  <a href=""><i class="material-icons">shopping_basket</i></a>  <a href=""><i class="material-icons">business</i></a>  <a href=""><i class="material-icons">mail</i></a>  <a href=""><i class="material-icons">card_giftcard</i></a></div>

What are the most important advantages of using flexbox instead of just using display: inline

...arguments why flexbox is a good alternative to the old inline/float-approach...

Why Flexbox?

For a long time, the only reliable cross-browser compatible tools
available for creating CSS layouts were features like floats and
positioning. These work, but in some ways they're also limiting and
frustrating.

The following simple layout designs are either difficult or impossible
to achieve with such tools in any kind of convenient, flexible way:

  • Vertically centering a block of content inside its parent.

  • Making all the children of a container take up an equal amount of the available width/height, regardless of how much width/height is
    available.

  • Making all columns in a multiple-column layout adopt the same height even if they contain a different amount of content.

MDN flexbox

Display flex is omitting spaces around the text value given in a span tag

For a more in-depth answer, please check out @Orial's post.

CSS flex box last space removed


The white-space processing model tells us:

If a space (U+0020) at the end of a line has white-space set to normal, nowrap, or pre-line, it is also removed.

To prevent this, use white-space: pre-wrap;:

.flex {
display: flex;
white-space: pre-wrap;
}

Demo: