Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add linear-gradient color to MUI Chip background?

I want to add linear-gradient below color to MUI Chip as a background color. Is it possible?

linear-gradient(to right bottom, #430089, #82ffa1)

I am using MUI v0.18.7.

<Chip backgroundColor={indigo400} style={{width: 120}}>
     <Avatar size={32} color={white} backgroundColor={indigo900}>A</Avatar>
     This is a Chip
</Chip>
like image 203
Hemadri Dasari Avatar asked Feb 18 '18 07:02

Hemadri Dasari


People also ask

How do you use a linear gradient for background color?

The linear-gradient() function sets a linear gradient as the background image. To create a linear gradient you must define at least two color stops. Color stops are the colors you want to render smooth transitions among. You can also set a starting point and a direction (or an angle) along with the gradient effect.

Can I use linear gradient with background image?

CSS gradients allow us to display smooth transitions between two or more colours. They can be added on top of the background image by simply combining the background-image URL and gradient properties.

How do I create a gradient fill background?

Click the “Design” pane on the main menu bar across your screen. Click on the “format background” option. Switch to “gradient fill” Create your custom gradient of two, three, or more colors by adding in color stops.

What color is the background image of a linear gradient?

It starts red, transitioning to yellow, then to blue: More "Try it Yourself" examples below. The linear-gradient () function sets a linear gradient as the background image.

How to test a color scheme with the Mui documentation?

To test a material.io/design/color color scheme with the MUI documentation, simply select colors using the palette and sliders below. Alternatively, you can enter hex values in the Primary and Secondary text fields. The output shown in the color sample can be pasted directly into a createTheme () function (to be used with ThemeProvider ):

How do I add a gradient background to an image?

Just set the background to the desired gradient in your styles: <Chip style= { {width: 120, background: 'linear-gradient (to right bottom, #430089, #82ffa1)'}}> <Avatar size= {32} color= {white} backgroundColor= {indigo900}>A</Avatar> This is a Chip </Chip> Note that linear-gradient is a CSS function that returns an image, not a color.

How to apply color to MUI icons?

Background color is also easy to apply to MUI Icons via the sx prop. I passed backgroundColor: "blue" in the example, but it could have taken a hex code like "#0000FF" or rgba color like "rgba (45, 85, 255, 1)". Hover color is not as simple to apply to MUI Icons as regular color styling.


2 Answers

Just set the background to the desired gradient in your styles:

<Chip style={{width: 120, background: 'linear-gradient(to right bottom, #430089, #82ffa1)'}}>
     <Avatar size={32} color={white} backgroundColor={indigo900}>A</Avatar>
     This is a Chip
</Chip>

Note that linear-gradient is a CSS function that returns an image, not a color. So, you have to set the background property (which takes an image) rather than the backgroundColor property (which takes just a color). Here's a quote from the Mozilla docs explaining this more thoroughly:

Because <gradient>s belong to the <image> data type, they can only be used where <image>s can be used. For this reason, linear-gradient() won't work on background-color and other properties that use the <color> data type.

like image 172
Jules Dupont Avatar answered Nov 19 '22 10:11

Jules Dupont


You can override any component in material-ui using classes. Instead of backgroundColor try this code.

//After imports statements
const style={
  chip:{
    background: 'linear-gradient(to right bottom, #430089, #82ffa1)',
  }
}
class Chips extends ...{
  render(){
const classes=this.props.classes;
  return(
    <Chip className={classes.chip}>
      <!--Content-->
     </Chip>
  );
  }
  }
like image 31
anonymous_siva Avatar answered Nov 19 '22 10:11

anonymous_siva