英文:
How to adjust height of material UI header with styles
问题
如何为MUI表格的表头设置样式,比如高度和宽度?
<TableHead >
<TableRow >
<TableCell hover>甜点 (100克份)</TableCell>
<TableCell align="right">卡路里</TableCell>
<TableCell align="right">脂肪 (克)</TableCell>
<TableCell align="right">碳水化合物 (克)</TableCell>
<TableCell align="right">蛋白质 (克)</TableCell>
</TableRow>
</TableHead>
我尝试传递
`sx={{
height: '20px'
}}`
但是高度仍然固定。
英文:
How can you style the header of a MUI table like height and width?
<TableHead >
<TableRow >
<TableCell hover>Dessert (100g serving)</TableCell>
<TableCell align="right">Calories</TableCell>
<TableCell align="right">Fat&nbsp;(g)</TableCell>
<TableCell align="right">Carbs&nbsp;(g)</TableCell>
<TableCell align="right">Protein&nbsp;(g)</TableCell>
</TableRow>
</TableHead>
I tried passing
sx={{
height:'20px'
}}
but the height is fixed
答案1
得分: 1
你可以通过在TableHead组件上使用sx来实现这个效果:
<TableHead sx={{height: "150px"}}>
<TableRow>
<TableCell hover>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>
英文:
You can achieve that by using sx on the TableHead component:
<TableHead sx={{height:"150px"}}>
<TableRow >
<TableCell hover>Dessert (100g serving)</TableCell>
<TableCell align="right">Calories</TableCell>
<TableCell align="right">Fat&nbsp;(g)</TableCell>
<TableCell align="right">Carbs&nbsp;(g)</TableCell>
<TableCell align="right">Protein&nbsp;(g)</TableCell>
</TableRow>
</TableHead>
答案2
得分: 0
要自定义TableHead
的样式,您需要定位Table
的**MuiTableCell-head
**类。
需要注意的一点是,Mui TableHead
的高度不是通过height
属性设置的,而是通过**line-height
**来设置的。请参考以下示例:
import { Table, TableHead, TableBody } from '@mui/material';
<Table sx={{ '& .MuiTableCell-head': { lineHeight: 20, color: 'red' } }}>
<TableHead>
</TableHead>
<TableBody>
</TableBody>
</Table>
英文:
To customize the styling of the TableHead
you need to target the MuiTableCell-head
class of the Table
.
One important thing to notice, Mui TableHead
height is not coming from the height
property, It is coming from line-height
. Please check the example below:
import { Table, TableHead, TableBody } from '@mui/material'
<Table sx={{ '& .MuiTableCell-head':{ lineHeight: 20, color: 'red' } }}>
<TableHead>
</TableHead>
<TableBody>
</TableBody>
</Table>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论