梅是新来的.我的元素似乎触到了手机屏幕的边缘.

https://codesandbox.io/s/proud-architecture-69b0jv?file=/App.js:2727-3108&resolutionWidth=748&resolutionHeight=675(纸元素在第94行)

 <Paper
   sx={{
   pt: 1,
   border: 1,
   boxShadow: 0,
   justifyContent: "center",
   margin: "auto",
   mt: 1,
   maxWidth: 800,
   flexGrow: 1,
   backgroundColor: (theme) =>
      theme.palette.mode === "dark" ? "#1A2027" : "#fff"
   }}
 >

image

推荐答案

我把你的纸包在一个小盒子里,给它一些填充物,这样你就可以保持自动边距和最大宽度.

return (
          //Main element
          <div style={{ padding: "0 5px" }}>
          <Paper
            sx={{
              pt: 1,
              border: 1,
              boxShadow: 0,
              margin: "auto",
              justifyContent: "center",
              mt: 1,
              maxWidth: 800,
              flexGrow: 1,
              backgroundColor: (theme) =>
                theme.palette.mode === "dark" ? "#1A2027" : "#fff"
            }}
          >
            <Grid container spacing={2}>
              <Grid item>
                <ButtonBase sx={{ width: 128, height: 128 }}>
                  <Img alt="complex" src={logo} />
                </ButtonBase>
              </Grid>
              <Grid item xs={12} sm container>
                <Grid item xs container direction="column" spacing={2}>
                  <Grid item xs>
                    <Typography
                      gutterBottom
                      variant="subtitle1"
                      component="div"
                    >
                      {post.flight_icao}
                    </Typography>

                    <Typography>{dtconvert}</Typography>

                    <Typography variant="body2" gutterBottom>
                      {post.dep_icao}
                    </Typography>

                    <Paper
                      sx={{
                        width: "-moz-fit-content",
                        width: "fit-content",
                        minWidth: 90,
                        boxShadow: 0,
                        borderRadius: 0,
                        backgroundColor: bs
                      }}
                    >
                      <Typography
                        variant="body2"
                        color="white"
                        sx={{
                          textAlign: "center",
                          fontWeight: "bold",
                          alignItems: "center",
                          display: "flex"
                        }}
                      >
                        <Img
                          alt="statusimg"
                          src={statusimg}
                          width={20}
                          height={20}
                          sx={{
                            mr: 0.4,
                            ml: 0.4
                          }}
                        />{" "}
                        {status}
                      </Typography>
                    </Paper>
                  </Grid>
                  <Grid item></Grid>
                </Grid>
                <Grid item>
                  <Typography
                    variant="subtitle1"
                    component="div"
                    sx={{ px: 2, p: 2 }}
                  >
                    {post.aircraft_icao}
                  </Typography>
                </Grid>
              </Grid>
            </Grid>
          </Paper>
          </div>
        );
      })}
    </div>
  );
}

export default App;

enter image description here

enter image description here

Css相关问答推荐

如何为 MUI Slider 字段中 markLabel 的第一个和最后一个实例提供边距?

尽管 URL 路径正确,但背景图像未显示

为什么 width: 100% 在 Flex 父级中缩小这个 div ?

Bootstrap 和 Sass:将 SCSS 文件转换为 CSS 时出错.错误:$theme-colors-rgb 中未定义变量 @each $color、$value

Tailwind CSS 不输出背景类

如何使用 Tailwind CSS 稳定 React 中的浮动标签?

如何阻止 Mud Blazor MudTable 列扩展以适合文本

带有 flex 的 CSS 空 div 以扩展并保持纵横比

背景上带有文本的按钮的反转 colored颜色

使用 CSS 填充悬停过渡的闪烁文本问题

用 svelte 设计 body 元素

左右卡片的 OwlCarousel 导航:react js

控制表格单元格之间的间距

如何保持包装的弹性项目与前一行元素的宽度相同?

twitter-bootstrap:当鼠标悬停在 -tag 中的 btn-group 上时,如何go 掉带下划线的按​​钮文本?

rotate3d 速记

CSS 表格 td 宽度 - 固定,不灵活

Select 器.class.class和.class.class有什么区别?

弹性框中的边距折叠

我应该在我的 Bootstrap 项目中使用 normalize.css 吗?