![](/img/trans.png)
[英]Bootstrap - How to horizontally align a Card that is inside a foreach?
[英]How to horizontally align card elements (rmwc) in React?
在我的父組件中:
{
this.state.projectList.map(dat => <Item data = {dat}/>)
}
在子組件Item
render() {
return (
<div style={{'width':'100%', 'textAlign':'center'}}>
<Card style={{ width: '25rem', padding: '1rem', display: 'inline-block' }}>
<CardPrimaryAction>
<div style={{ padding: '0 1rem 1rem 1rem' }}>
<Typography use="headline6" tag="h2">
{this.props.data.name}
</Typography>
<Typography use="body1" tag="div" theme="text-secondary-on-background">
{this.props.data.description}
</Typography>
</div>
</CardPrimaryAction>
</Card>
</div>
);
}
我正在使用rmwc
Card
組件來放置一些東西。
現在它只是像堆棧一樣垂直放置所有渲染的項目。 我真正想要的是圖像右側的藍色鋼筆小草圖。
我試圖給包裝div
'width':'100%', 'textAlign':'center'
和Card
本身一個inline-block
但它仍然是一樣的。
在父組件中,將您的地圖功能與 material-ui 的GridList
組件一起指定所需的列。 然后將您的數據包含在GridListTile
。 這如下圖所示,
<div>
<GridList cols={2} spacing={16}>
this.state.projectList.map(dat =>
<GridListTile item key={dat} xs={6}>
<Item data = {dat}/>
<GridListTile/>
))}
</GridList>
</div>
在子組件中,刪除父<div>
就可以了。 請務必導入必要的依賴項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.