The following is more of a general example.
<div> <div>Short dynamic text.</div> <div id="in-between">Possible long dynamic text...</div> <div>Short dynamic text.</div> </div>
It is possible to change the element order or type beforehand or add helpers in between. All text is not wrapped. It is not necessary to give a fixed width or height.
How to achieve this effect using only CSS instead of changing the DOM? So, how do you separate the middle element into a new line if the content doesn't fit? is it possible?
Some snippets could be explained in more detail and tested.
.example { display: flex; flex-wrap: wrap; column-gap: 0.5rem; justify-content: space-between; } .example .separate { flex-grow: 1; } .example .long-b { order: 1; /* this should happen by some magic */ } /* do not change below */ .container { border: 0.5rem solid black; background: blue; } .element { border: 0.5rem solid yellow; padding: 0.5rem; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .short-a:before { content: "only three words"; } .short-b:before { content: "flag"; } .short-c:before { content: "i love stackoverflow"; } .short-d:before { content: "attribute"; } .long-a:before { content: "i am not that long"; } .long-b:before { content: "i am very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long"; }
<div class="container example"> <div class="element short-a"></div> <div class="element separate long-a"></div> <div class="element short-b"></div> </div> <br /> <div class="container example"> <div class="element short-c"></div> <div class="element separate long-b"></div> <div class="element short-d"></div> </div>
The current answer is helpful and acceptable. However, are there (or will there be) other ways that don't utilize floats?
float is the only solution here, but you'll have to adjust the HTML structure (I know this goes against what you're asking for, but the following might give you some ideas)