You can get rid of the extra wrapper and do it like below:
const App = () => {
return (
<div className='container'>
<div className='square'>Content 1</div>
<div className='square'>Content 2</div>
<div className='square'>Content 3333</div>
<div className='square'>Content 44</div>
<div className='square'>Content 5</div>
</div>
)
}
ReactDOM.render(
<App />,
document.getElementById('app')
);
.container {
display: flex;
flex-direction: row;
}
.square {
display: flex;
justify-content: center;
align-items: center;
padding: 5px 9px;
height: 50px;
box-sizing:border-box;
background-color: blue;
margin: 2px 3%; /* 3% of margin between elements */
color:#fff;
min-width:0;
flex:1; /* eqaul width */
}
@media (max-width:800px) {
.container {
flex-wrap:wrap; /* allow the wrap*/
justify-content:center; /* center everything */
}
/* this will seperate both lines*/
.container::after {
content:"";
order:1;
width:100%;
}
/**/
/* the last 3 elements into the second line */
.square:nth-child(n + 3) {
order:2;
margin:2px;
}
/* give equal margin on both sides to have equal lines*/
.square:nth-child(1),
.square:nth-child(3){
margin:2px 2px 2px 15%;
}
.square:nth-child(2),
.square:nth-child(5){
margin:2px 15% 2px 2px;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.0/umd/react-dom.production.min.js"></script>
<div id="app"></div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…