Заставьте Предмет пойти вниз, используя Flexbox и Material UI - PullRequest
0 голосов
/ 29 мая 2019

Я пытаюсь добавить неназначенный текст внизу моего контейнера, как показано в этом макете: enter image description here

Ниже приведен код, который у меня есть до сих пор.Я изо всех сил пытаюсь заставить границу между кнопкой воспроизведения работать тоже.Я попробовал обычные css: bottom:0 и position:relevant Наряду с Flexbox, но, похоже, он не хочет идти к самому низу контейнера.

 const styles = theme => ({
  root: {
    flexGrow: 1,
    overflow: 'hidden',
    padding: theme.spacing(0, 3),
  },
  paper: {
    maxWidth: 800,
    margin: `${theme.spacing(2)}px auto`,
    padding: theme.spacing(2),
  },
  textField: {
    marginLeft: theme.spacing(1),
    marginRight: theme.spacing(1),
    width: 200,
  },
  playButton: {
    display: "flex",
    flexDirection: "column",
    justifyContent: "center",
    alignItems: "center",
    position: "relative",
    "& .playButton": {
      position: "absolute",
      top: "60%",
      left: "-55px",
      transform: "translateY(-50%)",
    },
      "& .star-rating": {
        "& .fa-star": {
          "&:hover": {
            "&::before": {
              content: "\f005",
              color: "yellow"
            }
          }
        }
      },
    },
});

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>
              {props.name}
              </Typography>
              <div className="form-divider"></div>
                <Typography variant="body2" color="textSecondary">
                {props.description}
                </Typography>
              </Grid>
            </Grid>
            <Grid item classes={{ root: props.classes.playButton}}>
    <Grid item xs={3} className="playButton">
      <i class="far fa-play-circle fa-2x"></i>
    </Grid>
    <div className="workers-assigned-label">
      Workers Assigned
    </div>
    <Typography variant="h6" gutterBottom>
        0/25
      </Typography>
      <div class="star-rating">
        <label class="far fa-star fa-2x"></label>
        <label class="far fa-star fa-2x"></label>
        <label class="far fa-star fa-2x"></label>
      </div>
    <div className="dropdown-menu">
  <h5>Unnassigned</h5>
</div>
  </Grid>
          </Grid>
        </Grid>
      </Paper>
    </div>
  );
}

export default withStyles(styles)(Tasks);

Любой вклад был бы великолепен.

Ответы [ 2 ]

1 голос
/ 29 мая 2019

Я бы порекомендовал начать с «скелета» сетки, который выглядит примерно так:

<Grid container>
  <Grid item container xs={8} direction="column" justify="flex-start">
    // Left column contents, with each row as a <Grid item>
  </Grid>
  <Fab className={classes.fab}><PlayIcon /><Fab>
  <Grid item container xs={4} direction="column" justify="space-between" className={classes.right}>
    // Right column contents, with each row as a <Grid item>
  </Grid>
</Grid>

direction=column поможет вам расположить элементы вертикально внутри каждого контейнера. justify=space-between гарантирует, что ваш первый элемент находится вверху контейнера, а ваш последний элемент (неназначенный текст) - внизу.

«Правильный» класс CSS выглядит так:

right: {
  borderLeft: `1px solid ${theme.palette.grey[500]}`,
  position: "relative"
}

Вы можете присвоить ему положение "относительный", чтобы упростить позиционирование потрясающего элемента относительно столбца. Класс "потрясающий" выглядит так:

fab: {
  position: "absolute",
  margin: "auto",
  top: 0,
  bottom: 0,
  left: -28
}

Свойства margin, top и bottom помогают центрировать фабрику по вертикали, а левая часть выглядит как хак, основываясь на размерах фабрики, чтобы центрировать ее над границей.

Вот рабочий проект, который объединяет все: https://codesandbox.io/s/tender-torvalds-dlbke?fontsize=14

0 голосов
/ 29 мая 2019

Вы можете попробовать что-то подобное или дать flex: 1 чему-либо в столбце, чтобы оно растянулось.

const styles = theme => ({
  playButton: {
    '& .dropdown-menu': {
      marginTop: "auto"
    }
  }
})
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...