Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize link hover underline highlight material-ui

I'm trying to follow material-ui custom styles and link but am not sure how to override classes and use withStyles

      <Breadcrumbs aria-label="breadcrumb" separator=" " className="menu">
        <Link color="inherit" href="/home">
          Home
        </Link>
      </Breadcrumbs>

I've modified global app.css file

a:hover{
  border-bottom: 1px solid red
}

And the outcome is like

Home
----
----  <- I have 2 underlines now when hovering over the link. The bottom one will be red.

How do I override this such as following?

Home
---- <- only 1 red underline shown when hovering over the link
like image 681
jen007 Avatar asked Aug 25 '26 00:08

jen007


2 Answers

For those not doing it through CSS but rather classes, you could do

link: {
    color: "#00ff00",
    "&:hover": {
        color: "#000000",
        textDecoration: "underline #000000"
    }
},
like image 74
foreverAnIntern Avatar answered Aug 26 '26 14:08

foreverAnIntern


Provide Material UI with a custom theme, as documented here.

The relevant bits for link hover underlining are:

import { createTheme } from "@mui/material";

export const myTheme = createTheme({
  components: {
    MuiLink: {
      styleOverrides: {
        root: {
          textDecoration: "none",
          ":hover": {
            textDecoration: "underline",
          },
        },
      },
    },
  },
});
like image 41
V Maharajh Avatar answered Aug 26 '26 15:08

V Maharajh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!