Используйте margin:auto
вот так:
.flex-container {
display: flex;
flex-wrap: wrap;
}
.flex-item:nth-child(2) {
margin-left: auto;
margin-right: 5px;
}
.flex-item:nth-child(3) {
margin-right: auto;
margin-left: 5px;
}
.flex-item {
line-height: 50px;
color: white;
background: pink;
font-weight: bold;
font-size: 2em;
text-align: center;
}
@media only screen and (max-width: 400px) {
.flex-container {
justify-content: center;
}
.flex-item:nth-child(n) {
margin: 5px;
}
}
<div class="flex-container">
<div class="flex-item"> text 1</div>
<div class="flex-item"> text 2</div>
<div class="flex-item"> text 3</div>
<div class="flex-item"> text 4</div>
</div>