Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI - Align icon to center with the Typography text

How do I align icon to the same level as the text. As of now, I see the icon is at little top to the text. I tried to use padding-top: 5px and also margin-top: 5px but that does not seem to work as expected.

  <Box>
    <Typography variant="h2">
      Photography <FaCamera />
    </Typography>
  </Box>

I created a working example using Stackblitz. Could anyone please help?

like image 998
coderpc Avatar asked Jan 23 '26 06:01

coderpc


2 Answers

<Typography variant="h2">
  Photography <FaCamera  style={{verticalAlign:"middle"}}/>
</Typography>

you can try inline style 'verticalAlign', it is works for me .

like image 57
will Avatar answered Jan 25 '26 00:01

will


I was able to align it correctly using position and top properties of CSS.

<Box>
  <Typography variant="h2">
    Photography <FaCamera style={{position: 'relative', top: '8px'}} />
  </Typography>
</Box>
like image 41
coderpc Avatar answered Jan 25 '26 00:01

coderpc