我目前正在尝试使用CSS网格在Material-UI中实现以下网格结构:
我已经使用Material-UI创建了如下所示的CSS网格:
这是它的代码:
import React from "react";
import clsx from "clsx";
import { makeStyles } from "@material-ui/core/styles";
import { Container } from "@material-ui/core";
const useStyles = makeStyles(theme => ({
container: {
marginTop: theme.spacing(8),
display: "grid",
gridTemplateColumns: "repeat(6, 56px)",
gridAutoRows: "56px",
gridGap: theme.spacing(0.5),
},
purple: {
background: "#e502f9",
color: "#ffffff",
height: "100%",
},
orange: {
background: "#f98202",
color: "#ffffff",
height: "100%",
gridColumnStart: "2",
},
lightGrey: {
background: "#d8d8d8",
height: "100%",
},
topLabel: {
gridColumnStart: "3",
gridColumnEnd: "span 4",
},
sideLabel: {
gridRowStart: "3",
gridRowEnd: "span 4",
writingMode: "vertical-rl",
transform: "rotate(180deg)",
},
align: {
alignItems: "center",
display: "flex",
justifyContent: "center",
textAlign: "center",
},
}));
function ExamplePage() {
const classes = useStyles();
return (
<Container component="main" maxWidth="xs">
<div className={classes.container}>
<div />
<div className={clsx(classes.topLabel, classes.align)}>
Text x-axis
</div>
<div className={clsx(classes.sideLabel, classes.align)}>
Text y-axis
</div>
<div />
<div />
<div className={clsx(classes.purple, classes.align)}>1</div>
<div className={clsx(classes.purple, classes.align)}>2</div>
<div className={clsx(classes.purple, classes.align)}>3</div>
<div className={clsx(classes.purple, classes.align)}>4</div>
<div className={clsx(classes.orange, classes.align)}>A</div>
<div className={clsx(classes.lightGrey, classes.align)}>4</div>
<div className={clsx(classes.lightGrey, classes.align)}>4</div>
<div className={clsx(classes.lightGrey, classes.align)}>4</div>
<div className={clsx(classes.lightGrey, classes.align)}>4</div>
<div className={clsx(classes.orange, classes.align)}>B</div>
<div className={clsx(classes.lightGrey, classes.align)}>3</div>
<div className={clsx(classes.lightGrey, classes.align)}>3</div>
<div className={clsx(classes.lightGrey, classes.align)}>3</div>
<div className={clsx(classes.lightGrey, classes.align)}>3</div>
<div className={clsx(classes.orange, classes.align)}>C</div>
<div className={clsx(classes.lightGrey, classes.align)}>2</div>
<div className={clsx(classes.lightGrey, classes.align)}>2</div>
<div className={clsx(classes.lightGrey, classes.align)}>2</div>
<div className={clsx(classes.lightGrey, classes.align)}>2</div>
<div className={clsx(classes.orange, classes.align)}>D</div>
<div className={clsx(classes.lightGrey, classes.align)}>1</div>
<div className={clsx(classes.lightGrey, classes.align)}>1</div>
<div className={clsx(classes.lightGrey, classes.align)}>1</div>
<div className={clsx(classes.lightGrey, classes.align)}>1</div>
</div>
</Container>
);
}
export default ExamplePage;
有人对如何以编程方式将蓝点设置在网格中的某个地方有想法吗?我不确定在CSS网格中是否完全可行?