I’m trying to add the hover effect to material icons but it does not work. I’m not sure what’s going wrong. Everything else looks great but I’m unable to see the hover effect. I’ve added my code below.
import ManageAccountsIcon from '@mui/icons-material/ManageAccounts';
import NotificationsIcon from '@mui/icons-material/Notifications';
import HelpIcon from '@mui/icons-material/Help';
const iconStyle =
{
"fontSize": "25px",
"color": "grey",
"padding-right":"30px",
"padding-top":"20px",
"cursor":"pointer",
"borderRadius": "10%",
"&:hover": { "color": "black" }
}
<HelpIcon style={iconStyle}/>
<NotificationsIcon style={iconStyle}/>
<ManageAccountsIcon style={iconStyle}/>
2
Answers
I found the solution. This code works when you use the sx keyword instead of style. So this works
You can’t use pseudoselectors (
&:hover
) in inline styles. This is not a limitation of React or Material UI but CSS itself.