javascript - Material UI - How to completely remove backgroundcolor from tooltip - Stack Overflow

I am currently working with Material UI's tooltip and I can't seem to figure out how to make

I am currently working with Material UI's tooltip and I can't seem to figure out how to make the tooltip's background pletely transparent. By default there is a grey background with white text. Changing the Tooltips background color changes the child element's background color since the Tooltip is the parent element in this context.

I've tried this

 <Tooltip title="Add" classes={{
    tooltip: "backgroundColor: transparent"

  }} aria-label="add">
    <Fab color="transparent" className={classes.fab}>
      <AddIcon />
    </Fab>
  </Tooltip>

And this:

<Tooltip title="Add" style={{backgroundColor: "transparent"}} aria-label="add">
    <Fab color="transparent" className={classes.fab}>
      <AddIcon />
    </Fab>
  </Tooltip>

My objective is to have no background on hover of the tooltip. I just want to see the text.

I am currently working with Material UI's tooltip and I can't seem to figure out how to make the tooltip's background pletely transparent. By default there is a grey background with white text. Changing the Tooltips background color changes the child element's background color since the Tooltip is the parent element in this context.

I've tried this

 <Tooltip title="Add" classes={{
    tooltip: "backgroundColor: transparent"

  }} aria-label="add">
    <Fab color="transparent" className={classes.fab}>
      <AddIcon />
    </Fab>
  </Tooltip>

And this:

<Tooltip title="Add" style={{backgroundColor: "transparent"}} aria-label="add">
    <Fab color="transparent" className={classes.fab}>
      <AddIcon />
    </Fab>
  </Tooltip>

My objective is to have no background on hover of the tooltip. I just want to see the text.

Share Improve this question asked Jan 9, 2020 at 15:37 MattMatt 991 gold badge2 silver badges8 bronze badges 1
  • 1 Does this answer your question? Material UI's Tooltip - Customization Style – Ryan Cogswell Commented Jan 9, 2020 at 15:48
Add a ment  | 

3 Answers 3

Reset to default 1

Since you want only the text on hover with no background of the tooltip.

Define style like this:

const useStylesBootstrap = makeStyles(theme => ({
  tooltip: {
    backgroundColor: "transparent",
    color: theme.palette.mon.black
  }
}));

Use it in your React ponent like this:

const tooltipClass = useStylesBootstrap();

return (
  <Tooltip title="Add" classes={tooltipClass} aria-label="add">
    <Fab color="transparent" className={classes.fab}>
      <AddIcon />
    </Fab>
  </Tooltip>
);

There are several methods for customizing ponents, as described in the documentation:

  1. Specific variation for a one-time situation
  2. Dynamic variation for a one-time situation
  3. Specific variation of a ponent re-used in different contexts
  4. Material Design variations such as with the button ponent
  5. Global theme variation

It appears you want to use the first method and override the style with a class. To do this we'll use makeStyles and define a background for the tooltip, something like this:

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Tooltip from '@material-ui/core/Tooltip';

const useStyles = makeStyles({
  tooltip: {
    background: 'transparent',
  },
});

export default function ClassesNesting() {
  const classes = useStyles();

  return (
    <Tooltip
      classes={classes}
    >
      Button
    </Tooltip>
  );
}

APP.css

Styles applied to the tooltip (label wrapper) element.

.MuiTooltip-tooltip {
    background-color: #EDEEEF!important;
    color: #2f343D!important;
  }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745099283a4611174.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信