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>
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.
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.
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.
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.
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 ):
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.
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.
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 onbackground-color
and other properties that use the<color>
data type.
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>
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With