【问题标题】:Too long title slide the menu button to the right outside of the card标题太长 将菜单按钮滑动到卡片右侧
【发布时间】:2020-08-13 12:32:25
【问题描述】:

我的 MuiCardHeader 有问题

<CardHeader
    disableTypography
    avatar={renderAvatar()}
    action={
        <IconButton onClick={toggleMenu}>
            <img src={MoreIcon} alt=""/>
        </IconButton>
    }
    title={
        <Typography noWrap variant="subtitle1">
            {data.name}
        </Typography>
    }
    subheader={
        <Typography variant="subtitle2" color="textSecondary">
            {data.children.items.length} items
        </Typography>
    }
/>

由于某种原因,标题或副标题过长,将菜单按钮滑动到卡片右侧。

如何预防?

我需要的结果

这里是代码沙箱

https://codesandbox.io/s/dazzling-paper-5d35h?file=/src/App.js

UPD:解决方案

添加以下代码

textOverflow: "ellipsis",
overflow: "hidden",
whiteSpace: "nowrap",

.MuiCardHeader-content

感谢大家的帮助!

【问题讨论】:

标签: javascript css reactjs material-ui


【解决方案1】:

您需要使用text-overflow: ellipsisoverflow: hiddenwhite-space: nowrap 限制父级

因此,在您的情况下,您只需将.MuiTypography-noWrap 添加到 .MuiCardHeader-content

【讨论】:

    猜你喜欢
    • 2022-11-04
    • 2015-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多