在带有媒体查询的网格列表中添加列

时间:2019-10-24 15:13:52

标签: reactjs material-ui

我是Ui材料的初学者。 我找不到如何使用媒体查询(在移动设备中为3,在桌面设备中为6)向“网格”列表中添加列的方法。 有人可以帮我吗?

import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import GridList from "@material-ui/core/GridList";
import GridListTile from "@material-ui/core/GridListTile";
import tileData from "./titleData";
import useMediaQuery from "@material-ui/core/useMediaQuery";

const useStyles = makeStyles(theme => ({
  root: {
    display: "flex",
    justifyContent: "center"
  },
  gridList: {
    width: 95 + "%",
    height: 450
  }
}));

export default function ImageGridList() {
  const classes = useStyles();

  return (
    <div className={classes.root}>
      <GridList cellHeight={160} className={classes.gridList} cols={3}>
        {tileData.map(tile => (
          <GridListTile key={tile.img} cols={tile.cols || 1}>
            <img src={tile.img} alt={tile.title} />
          </GridListTile>
        ))}
      </GridList>
    </div>
  );
}

0 个答案:

没有答案