I am trying using flexbox to horizontally center a menu but have its last element on the right side of the website.
Here is a schema:
I have tried setting the margin-left to auto on the last element but it sends the centered menu to the left. Setting margin-right to auto for the menu doesn't work.
I have a "hack"-solution: placing an invisible copy (visibility hidden) of the last element before the centered part of the menu and setting its margin-right to auto.
Any better hack-free solution?
Here is a code sample:
#container {
display: flex;
justify-content: center;
align-items: center;
}
#last {
margin-left: auto;
}
<div id="container">
<div id="menu">
<span>1</span>
<span>2</span>
<span>3</span>
</div>
<div id="last">
4
</div>
</div>
Thanks!