【问题标题】:How to 'justify-content: center' for MUI Pagination?如何为 MUI 分页“证明内容:中心”?
【发布时间】:2020-07-23 07:29:42
【问题描述】:

我正在尝试使分页的内容居中。但是,这不起作用。在控制台上,我需要证明 ul 包装器的合理性,但我在 MUI 网站上找不到与分页道具相关的任何信息或有关如何使项目居中的指南。

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Pagination from '@material-ui/lab/Pagination';

const useStyles = makeStyles((theme) => ({
  root: {
    '& > *': {
      marginTop: theme.spacing(2),
   
    },
  },
  pagination: {
    alignItems: 'center',
    justify: 'center',
  }
}));

const Paginated = (props) => {
  const classes = useStyles();
  return (
    <div className={classes.root}>
      <Pagination className={classes.pagination} count={props.totalPage} color='primary' />
    </div>
  );
};

export default Paginated;

我也一直在尝试使用代码沙盒。 https://codesandbox.io/s/material-demo-zv1ps?file=/demo.js

有没有什么方法可以做到这一点,而无需额外的盒子或网格包装器来包装它?

【问题讨论】:

    标签: reactjs material-ui


    【解决方案1】:

      root: {
        "& > *": {
          marginTop: theme.spacing(2),
          justifyContent:"center",
          display:'flex'
        }
      }

    【讨论】:

    • 感谢您的回答,我刚刚尝试过,但它没有居中:/
    • @GIHYUNNAM,检查我的答案
    • 哦,非常感谢。我错过了“显示:flex”!
    • 您能解释一下“& > *”的作用吗?
    【解决方案2】:

    margin: "auto" 为我工作

    root: {
      margin: "auto",
    },
    

    我从这里得到了这个想法:4 ways to center a component in Material-UI

    【讨论】:

      猜你喜欢
      • 2021-09-02
      • 2021-11-21
      • 2010-10-27
      • 2020-05-31
      • 1970-01-01
      • 2021-10-19
      • 1970-01-01
      • 2020-03-12
      • 1970-01-01
      相关资源
      最近更新 更多