How to add linear-gradient color to Slider?

╄→гoц情女王★ 提交于 2020-05-31 06:18:53

问题


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:


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 (
    <div className={classes.root}>
      <CustomSlider
        value={value}
        onChange={handleChange}
        aria-labelledby="continuous-slider"
      />
    </div>
  );
}



来源:https://stackoverflow.com/questions/59744468/how-to-add-linear-gradient-color-to-slider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!