How to add linear-gradient color to Slider?

前端 未结 1 1748
一向
一向 2021-01-22 08:22

I want to add linear-gradient to Material-UI Slider as color. Is it possible? I try everything.

color: \'linear-gradient(180deg, #29ABE2 0%, #00EAA6 100%)\'
         


        
1条回答
  •  清酒与你
    2021-01-22 09:11

    linear-gradient creates an image not a color. So you need to use it in CSS that specifies an image (e.g. background-image).

    Below is an example of a Slider using a gradient.

    import React from "react";
    import { makeStyles, withStyles } from "@material-ui/core/styles";
    import Slider from "@material-ui/core/Slider";
    
    const useStyles = makeStyles({
      root: {
        width: 200
      }
    });
    
    const CustomSlider = withStyles({
      rail: {
        backgroundImage: "linear-gradient(.25turn, #f00, #00f)"
      },
      track: {
        backgroundImage: "linear-gradient(.25turn, #f00, #00f)"
      }
    })(Slider);
    
    export default function ContinuousSlider() {
      const classes = useStyles();
      const [value, setValue] = React.useState(30);
    
      const handleChange = (event, newValue) => {
        setValue(newValue);
      };
    
      return (
        
    ); }

    0 讨论(0)
提交回复
热议问题