【问题标题】:How to centre play button using Material UI and Flexbox如何使用 Material UI 和 Flexbox 使播放按钮居中
【发布时间】:2019-10-13 22:24:57
【问题描述】:

我正在寻找有关此布局的一些建议。我正在努力将播放按钮放在边框中间。到目前为止,我有以下代码,我只是在努力让 flexbox 定位播放按钮。

    function Tasks(props) {
  const { classes } = props;
  return (
    <div className={classes.root}>
      <Paper className={classes.paper}>
        <Grid container spacing={2}>
          <Grid item xs={12} sm container>
            <Grid item xs container direction="column" spacing={2}>
              <Grid item xs>
              <div className="name-label">
              Name
              </div>
              <Typography variant="h6" gutterBottom>
              Order cofee beans
              </Typography>
              <div className="form-divider"></div>
                <Typography variant="body2" color="textSecondary">
                  Process of Description
                </Typography>
              </Grid>
            </Grid>
            <Grid item>
              <Typography variant="subtitle">Workers Assigned</Typography>
              <Grid item xs={3}>
        <i class="far fa-play-circle"></i>
      </Grid>
              <Typography variant="h6" gutterBottom>
              0/25</Typography>
            </Grid>
          </Grid>
        </Grid>
      </Paper>
    </div>
  );
}

目前,我不确定网格是否是问题所在,或者我是否需要更好地构建我所拥有的内容,任何反馈都将不胜感激。我有它应该是什么样子的图像:

Image

【问题讨论】:

    标签: css flexbox material-ui


    【解决方案1】:

    我不会像那样使用 flex 来定位按钮。看起来你想要这样的东西:

    const styles = theme => ({
      box1: {
        display: "flex",
        position: "relative",
        "& .playButton": {
          position: "absolute",
          top: "50%",
          transform: "translateY(-50%)"
        }
      }
    });
    
    const YourComponent = props => (
      <div>
        {...}
        <Grid item classes={{ root: props.classes.box1}}>
          <Typography variant="subtitle">Workers Assigned</Typography>
          <Grid item xs={3} className="playButton">
            <i class="far fa-play-circle"></i>
          </Grid>
          <Typography variant="h6" gutterBottom>0/25</Typography>
        </Grid>
        {...}
      </div>
    );
    
    YourComponent = withStyles(styles)(YourComponent);

    【讨论】:

    • 谢谢。我好像工作过。我现在只需要整理剩下的。
    猜你喜欢
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-01
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    相关资源
    最近更新 更多