自定义时间线纸张颜色

Posted

技术标签:

【中文标题】自定义时间线纸张颜色【英文标题】:Customize timeline Paper color 【发布时间】:2021-10-17 22:09:35 【问题描述】:

我想自定义这个自定义时间线的例子:

import React from 'react';
import  makeStyles  from '@material-ui/core/styles';
import Timeline from '@material-ui/lab/Timeline';
import TimelineItem from '@material-ui/lab/TimelineItem';
import TimelineSeparator from '@material-ui/lab/TimelineSeparator';
import TimelineConnector from '@material-ui/lab/TimelineConnector';
import TimelineContent from '@material-ui/lab/TimelineContent';
import TimelineOppositeContent from '@material-ui/lab/TimelineOppositeContent';
import TimelineDot from '@material-ui/lab/TimelineDot';
import FastfoodIcon from '@material-ui/icons/Fastfood';
import LaptopMacIcon from '@material-ui/icons/LaptopMac';
import HotelIcon from '@material-ui/icons/Hotel';
import RepeatIcon from '@material-ui/icons/Repeat';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';

const useStyles = makeStyles((theme) => (
  paper: 
    padding: '6px 16px',
  ,
  secondaryTail: 
    backgroundColor: theme.palette.secondary.main,
  ,
));

export default function CustomizedTimeline() 
  const classes = useStyles();

  return (
    <Timeline align="alternate">
      <TimelineItem>
        <TimelineOppositeContent>
          <Typography variant="body2" color="textSecondary">
            9:30 am
          </Typography>
        </TimelineOppositeContent>
        <TimelineSeparator>
          <TimelineDot>
            <FastfoodIcon />
          </TimelineDot>
          <TimelineConnector />
        </TimelineSeparator>
        <TimelineContent>
          <Paper elevation=3 className=classes.paper>
            <Typography variant="h6" component="h1">
              Eat
            </Typography>
            <Typography>Because you need strength</Typography>
          </Paper>
        </TimelineContent>
      </TimelineItem>
      <TimelineItem>
        <TimelineOppositeContent>
          <Typography variant="body2" color="textSecondary">
            10:00 am
          </Typography>
        </TimelineOppositeContent>
        <TimelineSeparator>
          <TimelineDot color="primary">
            <LaptopMacIcon />
          </TimelineDot>
          <TimelineConnector />
        </TimelineSeparator>
        <TimelineContent>
          <Paper elevation=3 className=classes.paper>
            <Typography variant="h6" component="h1">
              Code
            </Typography>
            <Typography>Because it&apos;s awesome!</Typography>
          </Paper>
        </TimelineContent>
      </TimelineItem>
      <TimelineItem>
        <TimelineSeparator>
          <TimelineDot color="primary" variant="outlined">
            <HotelIcon />
          </TimelineDot>
          <TimelineConnector className=classes.secondaryTail />
        </TimelineSeparator>
        <TimelineContent>
          <Paper elevation=3 className=classes.paper>
            <Typography variant="h6" component="h1">
              Sleep
            </Typography>
            <Typography>Because you need rest</Typography>
          </Paper>
        </TimelineContent>
      </TimelineItem>
      <TimelineItem>
        <TimelineSeparator>
          <TimelineDot color="secondary">
            <RepeatIcon />
          </TimelineDot>
        </TimelineSeparator>
        <TimelineContent>
          <Paper elevation=3 className=classes.paper>
            <Typography variant="h6" component="h1">
              Repeat
            </Typography>
            <Typography>Because this is the life you love!</Typography>
          </Paper>
        </TimelineContent>
      </TimelineItem>
    </Timeline>
  );

参考:https://material-ui.com/components/timeline/#timeline

你知道我如何将Paper 背景颜色设置为绿色或红色吗?

【问题讨论】:

你想改变这个颜色吗? nimb.ws/5cwQr4 是的,这个颜色。 这不就是一个简单的css问题吗?我错过了什么吗? 【参考方案1】:

你想这样做吗?

paper: 
  padding: "6px 16px",
  backgroundColor: "green"
,

代码沙盒:https://codesandbox.io/s/bold-greider-lce2u?file=/src/App.js

【讨论】:

以上是关于自定义时间线纸张颜色的主要内容,如果未能解决你的问题,请参考以下文章

EXCEL中纸张尺寸如何让设置自定义大小?

vis.js 时间线在项目上设置自定义背景颜色而不覆盖边框

打印机驱动程序 - 自定义纸张尺寸

UE4中多种颜色轮廓线的后期处理

python使用matplotlib可视化自定义设置坐标轴的范围自定义设置主坐标轴刻度和次坐标轴刻度自定义坐标轴刻度的显示样式自定义坐标轴刻度数值的颜色以及小数点位数添加坐标轴刻度网格线

python可视化自定义设置坐标轴的范围自定义设置主坐标轴刻度和次坐标轴刻度自定义坐标轴刻度的显示样式自定义坐标轴刻度数值的颜色以及小数点位数添加坐标轴刻度网格线自定义移动坐标轴的位置