The flex container behaves like a block element: it displays on a new line and takes up all of the space it can in the inline direction.
The flex items however are participating in a flex formatting context, because their parent is the element with display: flex
, which has an inner display type of flex
, establishing the flex formatting context for the direct children.
This is a paragraph. The browser renders this paragraph as a block box, so the paragraph begins on a new line, and expands to the full width available to it, ie, normal flow for a paragraph.
display: flex
.In this paragraph some of the words (this span has display: block
applied to it) have been wrapped in span elements.
In this next example we see how inline
elements behave. The span elements in this paragraph are inline by default, and as such, the span elements do not force line breaks.
<ul>
elementdisplay: inline-flex
Here are two paragraphs, both set to display: inline
.
The inline flex container and paragraphs all run together on one line rather than breaking onto new lines
The concept of margin collapsing.
There are a number of rules when margines will, and will not collapse.
This is a paragraph with a span inside this paragraph. A span is an inline element, and as such it will not respect the width & height properties.
display: inline-block
& display: block
This is a paragraph with a span inside this paragraph. A span is an inline element, and as such it will not respect the width & height properties. display: inline-block
This is a paragraph with a span inside this paragraph. A span is an inline element, and as such it will not respect the width & height properties. display: block