【发布时间】:2021-06-22 20:14:33
【问题描述】:
我在 reactjs 中使用 Material ui 主题有以下代码
const useStyles = makeStyles((theme) => ({
root2: {
maxWidth: 345,
flexGrow: 1
},
paper2: {
padding: theme.spacing(1),
color: theme.palette.text.secondary,
}
})
<div className={classes.root2}>
<Grid container spacing={3}>
<Grid item xs={12}>
<Paper className={classes.paper2}>
<Grid container alignItems="center" spacing={3}>
<Grid item>
<h3>Instructions</h3>
</Grid>
<Grid item>
<IconButton>
<ExpandMoreIcon />
</IconButton>
</Grid>
</Grid>
</Paper>
</Grid>
</Grid>
</div>
我想要的是
我在https://material-ui.com/system/flexbox/#flex-grow看到了一个例子
使用代码:
import React from 'react';
import Box from '@material-ui/core/Box';
export default function FlexGrow() {
return (
<div style={{ width: '100%' }}>
<Box display="flex" p={1} bgcolor="background.paper">
<Box p={1} flexGrow={1} bgcolor="grey.300">
Item 1
</Box>
<Box p={1} bgcolor="grey.300">
Item 2
</Box>
<Box p={1} bgcolor="grey.300">
Item 3
</Box>
</Box>
</div>
);
}
我是材料 ui 的新手。这里的示例使用 Box 而不是 Grid。
那么处理这个问题的最佳方法是什么
我习惯于 bootstrap 4:在 bootstrap4 中我可以使用
https://getbootstrap.com/docs/4.4/utilities/flex/#justify-content
<div class="d-flex justify-content-between">...</div>
如何在 Material UI 中做这样的事情
【问题讨论】:
-
在父容器上使用flexbox并添加属性为
display: flex;,justify-content: space-between。
标签: reactjs material-ui