如何使用材料UI并排显示2个表格?
我想使用材料UI并排有2个表格。
这是桌子。
function BasicTable() {
return (
<TableContainer component={Paper}>
<Table sx={{ minWidth: 300 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>Dessert (100g serving)</TableCell>
<TableCell align="right">Calories</TableCell>
<TableCell align="right">Fat (g)</TableCell>
<TableCell align="right">Carbs (g)</TableCell>
<TableCell align="right">Protein (g)</TableCell>
</TableRow>
</TableHead>
<TableBody>
{rows.map((row) => (
<TableRow
key={row.name}
sx={{ '&:last-child td, &:last-child th': { border: 0} }}
>
<TableCell component="th" scope="row">
{row.name}
</TableCell>
<TableCell align="right">{row.calories}</TableCell>
<TableCell align="right">{row.fat}</TableCell>
<TableCell align="right">{row.carbs}</TableCell>
<TableCell align="right">{row.protein}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
);
}
这是我两次并排显示表的代码。
<Box
sx={{
float:'left',
clear: 'both',
p:10,
m:5,
bgcolor: 'background.paper',
borderRadius: 1,
display: 'inline-flex',
direction:'row' }}>
<BasicTable/>
</Box>
<Box
sx={{
float: 'right',
clear: 'both',
width:'200',
//display: table,
p:10,
m:5,
bgcolor: 'background.paper',
borderRadius: 1,
display: 'inline-block',
direction:'row'
// width:'50%'
}}
>
<BasicTable/>
</Box>
我只能实现这一目标
。而且它很难在不使用CSS文件的情况下格式化。任何帮助将不胜感激。谢谢。
I want to have 2 tables side by side in React using Material UI.
This is the table.
function BasicTable() {
return (
<TableContainer component={Paper}>
<Table sx={{ minWidth: 300 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>Dessert (100g serving)</TableCell>
<TableCell align="right">Calories</TableCell>
<TableCell align="right">Fat (g)</TableCell>
<TableCell align="right">Carbs (g)</TableCell>
<TableCell align="right">Protein (g)</TableCell>
</TableRow>
</TableHead>
<TableBody>
{rows.map((row) => (
<TableRow
key={row.name}
sx={{ '&:last-child td, &:last-child th': { border: 0} }}
>
<TableCell component="th" scope="row">
{row.name}
</TableCell>
<TableCell align="right">{row.calories}</TableCell>
<TableCell align="right">{row.fat}</TableCell>
<TableCell align="right">{row.carbs}</TableCell>
<TableCell align="right">{row.protein}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
);
}
This is my code for displaying the table twice side by side.
<Box
sx={{
float:'left',
clear: 'both',
p:10,
m:5,
bgcolor: 'background.paper',
borderRadius: 1,
display: 'inline-flex',
direction:'row' }}>
<BasicTable/>
</Box>
<Box
sx={{
float: 'right',
clear: 'both',
width:'200',
//display: table,
p:10,
m:5,
bgcolor: 'background.paper',
borderRadius: 1,
display: 'inline-block',
direction:'row'
// width:'50%'
}}
>
<BasicTable/>
</Box>
I'm only quite able to achieve this.currently looks like
I'm new to Material UI and its so hard to format without using a CSS file. Any help would be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
网格
而不是框。You can use
Grid
rather than Box.您也可以使用
stack
:You can use
Stack
too: