【发布时间】:2020-11-14 17:03:22
【问题描述】:
我正在使用 Material-UI 在 React 中构建一个网站。我有一张表格,想知道是否可以设置列宽以适应数据+两端的一些额外填充?
这是我的桌子:
<Table className={classes.table} size="small">
<TableHead>
<TableRow>
<TableCell width="???">CA</TableCell> <--- Width should be as much as "Fit to data" + margin of X pixels
<TableCell width="140px">CB</TableCell>
<TableCell width="240px">CC</TableCell>
<TableCell width="200px">CD</TableCell>
<TableCell>CE</TableCell>
</TableRow>
</TableHead>
<TableBody>
{data.map((row) => (
<TableRow key={row.id}>
<TableCell>{row.ca}</TableCell>
<TableCell>{row.cb}</TableCell>
<TableCell>{row.cc}</TableCell>
<TableCell>{row.cd}</TableCell>
<TableCell>{row.ce}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
我希望CA 列最小化,这样它就可以在两边留出额外的空间来容纳数据,这样内容就不会触及列边界。
我试过了:
- 根本没有声明
width- 没用 -
width="auto"- 没用
【问题讨论】:
标签: javascript css reactjs material-ui