[英]Align content to center with variant as caption in Material UI Typography
[英]Material UI - Align icon to center with the Typography text
如何将图标对齐到与文本相同的水平。 截至目前,我看到图标位于文本的顶部。 我尝试使用padding-top: 5px
和margin-top: 5px
但这似乎没有按预期工作。
<Box>
<Typography variant="h2">
Photography <FaCamera />
</Typography>
</Box>
我使用Stackblitz创建了一个工作示例。 有人可以帮忙吗?
我能够使用 CSS 的position
和top
属性正确对齐它。
<Box>
<Typography variant="h2">
Photography <FaCamera style={{position: 'relative', top: '8px'}} />
</Typography>
</Box>
您可以轻松地使用 Grid 来实现正确的对齐,而无需任何 CSS。
<Grid container alignItems="center" spacing={2}>
<Grid item>
<Typography variant="h2">
Photography
</Typography>
</Grid>
<Grid item>
<FaCamera />
</Grid>
</Grid>
只需在您的内联图标上执行fontSize="inherit"
,例如: <FaCamera fontSize="inherit" />
<Typography variant="h2">
Photography <FaCamera style={{verticalAlign:"middle"}}/>
</Typography>
您可以尝试内联样式“verticalAlign”,它对我有用。
从@mui/icons-material
导入图标时,我遇到了同样的问题。
设置fontSize: 'inherit'
使图标与字体大小相同。 仍然存在轻微的垂直 alignment 问题,我可以通过使用verticalAlign: 'text-top'
来解决。
对我有用的代码是:
<Icon sx={{ fontSize: 'inherit', verticalAlign: 'text-top' }} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.