I got a responsive design, which has 3 items in a row. If the screen gets smaller, the first one will be deleted. So the 3 items are distributed with flexbox and justify-content:space-between
, which makes the outer items bound to the sides and the middle item centered. Now if the first item is deleted, I want to be the right item on the right side and the left item centered to the space which is left.
This is my code for the 3 items:
<div style="display:flex;flex-flow:row;justify-content:space-between;align-items:center">
<span style="width:70px;text-align:right">To the left</span>
<div style="height:40px;width:100px;background-color:red">Center</div>
<span style="width:70px;text-align:right">To the right</span>
</div>
And this for the two items:
<div style="display:flex;flex-flow:row;justify-content:space-between;align-items:center">
<div style="height:40px;width:100px;background-color:red">Center</div>
<span style="width:70px;text-align:right">To the right</span>
</div>
I got some fiddle for you: https://jsfiddle.net/msLd7g5j/1/
Edit: Note this is not a duplicate, at least not to the one you pointed out, because I want the left item centered to the space which is 'left over' and not centered absolutely.
Solution: I got a new fiddle: https://jsfiddle.net/msLd7g5j/2/
I just don't delete the third element, instead I delete the content, so the Element looks like
<span> </span>
the flexbox just does it job and centers the middle element to the relative middle, with justify-content:space-between
set.