Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wrap text around objects (like floating does) in flexbox?

Tags:

html

css

flexbox

Let's say I have a display: inline container with some text children, and some inline-block children:

enter image description here

If I give the container the following CSS... (and change inline-block to inline-flex)

display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;

... then it treats the text element as an entire element of its own and wraps the whole thing, rather than breaking it up.

enter image description here

Is there a "flexbox" way of achieving this, or do I really have to fall back to display inline?

like image 895
Andrew Rasmussen Avatar asked Jan 14 '18 20:01

Andrew Rasmussen


1 Answers

Once you create a flex container (display: flex or display: inline-flex), all in-flow children become flex items.

Flex items are, by definition, "blockified", which means they are block-level boxes (source).

Text elements represent inline-level boxes (source).

Therefore, you cannot make flex items wrap in the same way as text (or floats).

like image 86
Michael Benjamin Avatar answered Sep 21 '22 07:09

Michael Benjamin