【问题标题】:Align items into table将项目对齐到表格中
【发布时间】:2021-11-16 17:10:01
【问题描述】:

我想实现一个基本表,其中列出项目作为键值:

import React, {FormEvent} from 'react';
import {Box, Button, Container, Grid, TextField, Typography} from '@material-ui/core';

export default function Hello( ) {
 
  return (
      <Container>
                      <Grid container
                            direction="column"
                            justifyContent="space-between"
                            alignItems="flex-start">

                          <Grid item>
                              <Box pl={2} pb={3}>
                                  <Typography variant="h4">
                                      Summary
                                  </Typography>
                              </Box>
                          </Grid>
                      </Grid>

                     

                      <Grid item>
                          <Grid
                              container
                              direction="row"
                              justifyContent="flex-start"
                              alignItems="flex-start"
                          >
                              <Grid item>
                                  <Box component="div"
                                       sx={{display: 'inline', p: 2, m: 2}}
                                  >
                                      Country 123
                                  </Box>

                              </Grid>
                              <Grid item>
                                  <Box component="div"
                                       sx={{display: 'inline', p: 2, m: 2}}
                                  >
                                      USA
                                  </Box>
                              </Grid>
                          </Grid>
                      </Grid>
 

                      <Grid item>
                          <Grid
                              container
                              direction="row"
                              justifyContent="flex-start"
                              alignItems="flex-start"
                          >
                              <Grid item>
                                  <Box component="div"
                                       sx={{display: 'inline', p: 2, m: 2}}
                                  >
                                      Country 4323
                                  </Box>

                              </Grid>
                              <Grid item>
                                  <Box component="div"
                                       sx={{display: 'inline', p: 2, m: 2}}
                                  >
                                      USA
                                  </Box>
                              </Grid>
                          </Grid>
                      </Grid>

                     

                      <Grid item>
                          <Grid
                              container
                              direction="row"
                              justifyContent="flex-start"
                              alignItems="flex-start"
                          >
                              <Grid item>
                                  <Box component="div"
                                       sx={{display: 'inline', p: 2, m: 2}}
                                  >
                                      Country
                                  </Box>

                              </Grid>
                              <Grid item>
                                  <Box component="div"
                                       sx={{display: 'inline', p: 2, m: 2}}
                                  >
                                      USA
                                  </Box>
                              </Grid>
                          </Grid>
                      </Grid>
 
         
      </Container>
  )
}

沙盒:https://stackblitz.com/edit/react-ts-srtlsp?file=Hello.tsx

我有不同大小的值,它们会推动其他值。是否可以在不推送其他值的情况下拥有不同大小的字符串?

有没有更好的方法来实现这个功能?

【问题讨论】:

  • 为什么不用Table组件?
  • 我可以使用它,但我需要从表中删除所有 css。 Cna你给我一些例子请怎么做?
  • 删除所有css是什么意思?您要删除所有边框还是其他任何内容?
  • 是的,我想去掉边框。
  • this问题。

标签: javascript reactjs material-ui react-typescript


【解决方案1】:

首先我建议您为此使用表格而不是网格。但是,如果您想完成这项工作,请为您的框指定固定宽度,如下所示:

     <Box
              component="div"
              sx={{ display: 'inline-', p: 2, m: 2, width: 100 }}
            >
              Country 4323
    </Box>

现在它们将是 inline ,因为设置了宽度。请注意,宽度应始终大于您放入框中的内容。

【讨论】:

  • 你能告诉我如何让 Materia-UI 表透明吗?
  • @PeterPenzov MU 对你来说是必须的吗?在这种情况下,纯 Html 和 CSS 要容易得多。
  • 是的,我想在这个项目中使用 Material UI。
猜你喜欢
  • 1970-01-01
  • 2015-11-11
  • 1970-01-01
  • 1970-01-01
  • 2021-02-21
  • 2019-05-04
  • 2018-04-22
  • 2021-09-05
  • 1970-01-01
相关资源
最近更新 更多