亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Material UI 如何設置網格元素垂直跨3行?

Material UI 如何設置網格元素垂直跨3行?

九州編程 2023-10-17 16:00:07
這似乎是一個基本問題,但在 Material UI 的官方文檔中沒有如何實現這一點的示例。我嘗試過嵌套網格,但右側的網格元素不會跨越垂直空間。我嘗試過align-items =“stretch”。下面是屏幕截圖和我的代碼。感謝您的任何建議!return (<Container>  <Box>    <Typography>Test</Typography>  </Box>  <Grid container spacing={3} direction="row" justify="center" alignItems="stretch">    <Grid item xs={12}>      <Paper className={classes.paper}>xs=12</Paper>    </Grid>    <Grid item xs={6} spacing={3}>      <Grid>        <Card className={classes.root} variant="outlined">          <CardContent>          <Typography className={classes.title} color="textSecondary" gutterBottom>            Customer Profile          </Typography>          <Typography variant="h5" component="h2">            Sarah Doria          </Typography>          <Typography className={classes.pos} color="textSecondary">            Position          </Typography>          <Typography variant="body2" component="p">            Company            <br />            {'"a benevolent smile"'}          </Typography>          </CardContent>          <CardActions>            <Button size="small">Learn More</Button>          </CardActions>        </Card>    </Grid>
查看完整描述

1 回答

?
幕布斯7119047

TA貢獻1794條經驗 獲得超8個贊

只需添加height 100%卡片和網格


<Grid style={{ height: "100%" }}>


<Card style={{ height: "100%" }}>

import React from "react";

import "./styles.css";

import {

  Grid,

  Typography,

  Container,

  Box,

  Paper,

  Card,

  CardContent,

  CardActions,

  Button

} from "@material-ui/core";


const YourCard = () => {

  const classes = {};

  return (

    <Card

      className={classes.root}

      variant="outlined"

      style={{ height: "100%" }}

    >

      <CardContent>

        <Typography

          className={classes.title}

          color="textSecondary"

          gutterBottom

        >

          Customer Profile

        </Typography>

        <Typography variant="h5" component="h2">

          Sarah Doria

        </Typography>

        <Typography className={classes.pos} color="textSecondary">

          Position

        </Typography>

        <Typography variant="body2" component="p">

          Company

          <br />

          {'"a benevolent smile"'}

        </Typography>

      </CardContent>

      <CardActions>

        <Button size="small">Learn More</Button>

      </CardActions>

    </Card>

  );

};


export default function App() {

  const classes = {};

  return (

    <Container>

      <Box>

        <Typography>Test</Typography>

      </Box>

      <Grid

        container

        spacing={3}

        direction="row"

        justify="center"

        alignItems="stretch"

      >

        <Grid item xs={12}>

          <Paper className={classes.paper}>xs=12</Paper>

        </Grid>

        <Grid item xs={6}>

          <Grid container spacing={3}>

            <Grid item xs={12}>

              <YourCard />

            </Grid>

            <Grid item xs={12}>

              <YourCard />

            </Grid>

            <Grid item xs={12}>

              <YourCard />

            </Grid>

          </Grid>

        </Grid>

        <Grid item xs={6}>

          <Grid style={{ height: "100%" }}>

            <YourCard />

          </Grid>

        </Grid>

      </Grid>

    </Container>

  );

}

https://img1.sycdn.imooc.com/652e3f60000117bd06490741.jpg

查看完整回答
反對 回復 2023-10-17
  • 1 回答
  • 0 關注
  • 115 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號