【问题标题】:How to style the badge component?如何设置徽章组件的样式?
【发布时间】:2019-07-17 12:46:18
【问题描述】:

我想让 Material ui 徽章与样式 right:'inherit' 一起使用

为此,我需要覆盖徽章样式,但这些在根节点上不可用。例如,我的课程被应用于父垃圾邮件而不是子徽章跨度。

<span class="MuiBadge-root makeStyles-listItemContentContainer-152"><div class="MuiPaper-root MuiPaper-elevation1 makeStyles-listItemContent-151 MuiPaper-rounded">
<span class="makeStyles-itemHeader-153">Switch to LED lights</span><span class="makeStyles-itemDescription-154">LED Bulbs last 3 times longer than CFL bulbs.
<button class="MuiButtonBase-root MuiButton-root makeStyles-readMore-155 MuiButton-text" tabindex="0" type="button">
<span class="MuiButton-label"> Read More </span></button>
</span></div><span class="MuiBadge-badge MuiBadge-colorPrimary">Insights</span></span>`enter code here`

【问题讨论】:

    标签: reactjs material-ui badge


    【解决方案1】:

    您可以使用 classes 属性将样式添加到内部跨度:

    <Badge badgeContent={"11"} classes={{badge: classes.myBadge}}>
    

    myBadge 在 makeStyles 中定义:

    const useStyles = makeStyles((theme) => ({
      myBadge:{
        right: "inherit",
      }
    }));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      • 2016-11-12
      • 2010-11-19
      相关资源
      最近更新 更多