reactjs - 如何根据reactjs中显示的内容拉伸(stretch)卡片?

标签 reactjs

我是 Material UI 框架的新手,我想相应地拉伸(stretch)内容中显示的网格。我做不到。有人可以帮我吗?

<Card>
        <CardHeader
          avatar={<Avatar aria-label="recipe">S</Avatar>}
          title={
            <>
              <InputBase placeholder="Search Google Maps" margin="normal" />
              <IconButton type="submit" aria-label="search">
                <SearchIcon />
              </IconButton>
            </>
          }
        />
        <Divider />
        <CardContent
          style={{ overflow: "scroll" }}
          className={classes.contentHeight}
          id="chatList"
        >
          <div>
            <Message isSender content="Hello" />
            {this.state.data.map(item => {
              if (item.isSender) {
                return (
                  <Message isSender name="Sanjana" content={item.content} />
                );
              }
              return <Message name="Sanjana" content={item.content} />;
            })}
          </div>
        </CardContent>
        <Divider />
        <CardActions>
          <Paper className={classes.contentPaper}>
            <Input
              margin="dense"
              className={classes.input}
              placeholder="Enter a Message"
              disableUnderline
            />
          </Paper>
        </CardActions>
      </Card>

有人可以帮我解决这个问题吗?

提前致谢!

最佳答案

要使内容拉伸(stretch)全宽度,您可以使用 width: "fit-content" 并将 width 值 100 分配给 minWidth: 100 .

所以你的卡片看起来像,

        <Card
          style={{
            backgroundColor: "#eee",
            float: isSender ? "right" : "left",
            padding: 16,
            diaplay: "block",
            minHeight: 40,
            width: "fit-content",
            minWidth: 100,
            display: "flex",
            alignItems: "center",
            textAlign: "center"
          }}
        >

要使内容在卡片内左对齐,您可以将样式指定给Grid,例如,

 <Grid style={{ paddingBottom: 8, textAlign: "left" }} item xs={12}>
        <span>{name}</span>
 </Grid>

Forked sandbox

关于reactjs - 如何根据reactjs中显示的内容拉伸(stretch)卡片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60985696/

相关文章:

javascript - 类型 'Group' 上不存在属性 'ForwardRefExoticComponent<InputProps & RefAttributes<HTMLInputElement>>'

javascript - Reactjs:带有复选框的setState:选中或未选中

node.js - React Nodejs - jsx 中的自定义 @font-face 用于 PDF 生成

reactjs - 当用户登录 React js 时,防止用户返回登录页面

javascript - ReactJs/Typescript 如何将对象数组传递到界面 Prop 中?

node.js - 在 React Native 和 NodeJS 后端使用 Google 登录

reactjs - Material ui select onchange 不冒泡

javascript - React 应用程序中 Adyen 的 Checkout SDK 集成

javascript - 为什么我在 for...of 循环中收到 'no-unused-vars' 警告,我该如何解决?

reactjs - 如何在Elastic Search中存储用户执行的操作?