If you want the following result

the, the following solution would work.
.container {
background-color: wheat;
width: 10rem;
height: 5rem;
margin-top: 5rem;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.item {
width: 2rem;
height: 2rem;
background-color: thistle;
border: 0.1rem solid gray;
padding: 1rem;
display: flex;
justify-content: center;
align-items: center;
}
.item:nth-child(5) {
position: absolute;
top: 50%;
left: 95%;
transform: translateY(-50%);
}
In the code above, I have used absolute
positioning for the 5th item, so that it is taken out of the normal flow of the document and we can position it using top
, left
, right
and bottom
properties. Make sure to add position:relative
to the parent container.
I have centered the 5th item on the center of the container using transform:translateY(-50%)
. You can decide how far you want to position the 5th element from the left by changing the left
property.
And the reason margin-left:auto
does not work, because when you use it, the 5th item takes as much space as possible towards its left and therefore the rest of the 4 items get pushed to the left/beginning of the container.