【发布时间】:2020-06-03 04:16:04
【问题描述】:
我想将 UI 显示为图片,并且我使用循环来创建 div ,所以我认为 flex 是最有说服力的方法。每行显示四个元素,我想将每个弹性项目的边距(左上右下)设置为相同的 10 像素。我尝试了 justify-content:space-between / space-around。这些都不是我想要的。
class App extends Component {
constructor() {
super();
this.arr = [1, 2, 3, 4, 5];
}
createDiv = () => {
// return div className="child" />
};
render() {
return (
<div className="contianer">
{this.arr.map((item, index) => (
<div className="child" />
))}
</div>
);
}
}
.contianer{
/* width: calc(100%-20px); */
display:flex;
flex-flow: row wrap;
background-color: gray;
justify-content: space-between
/* flex:1; */
}
.child{
background-color: yellow;
width: calc((100% - 50px) / 4);
height: 100px;
margin: 10px 5px
}
在线演示:https://stackblitz.com/edit/react-fapbff
所以有办法实现我想要的吗?
【问题讨论】: