【问题标题】:Material UI Grid List Rows with a big awkward gapMaterial UI Grid List Rows 有一个很大的尴尬差距
【发布时间】:2018-06-10 16:34:06
【问题描述】:

我正在使用带有 Reactjs 的 Material UI。我对网格列表组件有疑问。我试图有一个网格 - 1000x1000px,所以我在文档中将自定义 gridList 样式中的高度和宽度分别指定为 1000 和 1000。应该有 10 列,每个单元格的高度应为 100 像素。

当我在网格列表中有超过 1 行时出现问题。行元素之间的间隙太大。我试图覆盖 CSS 样式,但它们都不能很好地工作。我希望网格单元的行在彼此的正下方堆叠,而不是在它们之间有这么大的间隙。

点击这里查看awkward cell row gap

这是我的代码,

import React, { Component } from 'react';
import { connect } from 'react-redux';
import * as actions from '../actions';
import {GridList, GridTile} from 'material-ui/GridList';
import { Container } from 'semantic-ui-react';

const styles = {
  root: {
    "display": 'flex',
    "flexWrap": 'wrap',
    "justifyContent": 'space-around',
  },
  gridList: {
    "width": 1000,
    "height": 1000,
    "overflowY": 'auto',
  },
  indvCell: {
    "borderRadius": 25,
  }
};

const tilesData = [
  {
    img: '/img/sample/alex-wong-17993.jpg',
    title: 'Breakfast',
    author: 'jill111',
  },
  {
    img: '/img/sample/casey-horner-339165.jpg',
    title: 'Tasty burger',
    author: 'pashminu',
  },
  {
    img: '/img/sample/danny-postma-302063.jpg',
    title: 'Camera',
    author: 'Danson67',
  },
  {
    img: '/img/sample/derek-thomson-330312.jpg',
    title: 'Morning',
    author: 'fancycrave1',
  },
  {
    img: '/img/sample/hermansyah-352364.jpg',
    title: 'Hats',
    author: 'Hans',
  },
  {
    img: '/img/sample/kalen-emsley-99660.jpg',
    title: 'Honey',
    author: 'fancycravel',
  },
  {
    img: '/img/sample/lachlan-dempsey-397956.jpg',
    title: 'Vegetables',
    author: 'jill111',
  },
  {
    img: '/img/sample/linas-bam-223729.jpg',
    title: 'Water plant',
    author: 'BkrmadtyaKarki',
  },
  {
    img: '/img/sample/michal-kmet-257136.jpg',
    title: 'Water plant',
    author: 'BkrmadtyaKarki',
  },
  {
    img: '/img/sample/mohdammed-ali-340700.jpg',
    title: 'Water plant',
    author: 'BkrmadtyaKarki',
  },
  {
    img: '/img/sample/ng-55633.jpg',
    title: 'Water plant',
    author: 'BkrmadtyaKarki',
  },
  {
    img: '/img/sample/xan-griffin-419096.jpg',
    title: 'Water plant',
    author: 'BkrmadtyaKarki',
  },
];

class Blocks extends Component {

  render() {
    return (
      <Container>
        <div style={styles.root}>
          <GridList
            cellHeight={100}
            style={styles.gridList}
            cols={10}
          >
            {tilesData.map((tile) => (
              <GridTile
                key={tile.img}
                style={styles.indvCell}
              >
                <img src={tile.img} />
              </GridTile>
            ))}
          </GridList>
          </div>
      </Container>
    );
  }
}

我的 Material UI 版本是"material-ui": "^0.20.0"

【问题讨论】:

  • 你可以在stackblitz.com 中尝试你的简单代码并在这里分享吗?
  • 下面的答案有效

标签: css reactjs user-interface responsive-design material-ui


【解决方案1】:

这种情况下的问题是 gridList 样式中定义的高度,它迫使容器将单元格容器向外拉伸。删除它或将其设置为自动修复间距:

const styles = {
  root: {
    "display": 'flex',
    "flexWrap": 'wrap',
    "justifyContent": 'space-around',
  },
  gridList: {
    "width": 1000,
    "height": 'auto',
    "overflowY": 'auto',
  },
  indvCell: {
    "borderRadius": 25,
  }
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多