Material UI:在两个 Typography 组件之间放置一个空间

eta*_*luz 11 reactjs material-ui

如何在两个 Typography 组件之间添加一个空格并将它们对齐到底部?

这是我的代码:

  <div style={{ display: "flex" }}>
    <Typography variant="title" color="inherit" noWrap>
      Project:
    </Typography>
    <Typography variant="body 2" color="inherit" noWrap>
      Example
    </Typography>
  </div>
Run Code Online (Sandbox Code Playgroud)

它看起来像这样: 在此处输入图片说明

工作示例:https : //codesandbox.io/s/llqry78p29

sma*_*c89 8

只需添加一个只有空白的版式元素:

<div style={{ display: "flex" }}>
  <Typography variant="title" color="inherit" noWrap>
    Project:
  </Typography>
  <Typography variant="title" color="inherit" noWrap>
    &nbsp;
  </Typography>
  <Typography variant="body2" color="inherit" noWrap>
    Example
  </Typography>
</div>
Run Code Online (Sandbox Code Playgroud)


Arm*_*mel 6

这个问题有点老了,但我面临着同样的问题,所以我会发布我的解决方案。我使用了 flex 属性:

align-items: baseline;
Run Code Online (Sandbox Code Playgroud)

所以代码会是这样的:

<div style={{ display: "flex", alignItems: "baseline" }}>
   ...
</div>
Run Code Online (Sandbox Code Playgroud)

结果如下: 在此输入图像描述

评论中提到的解决方案align-items: flex-end没有给我预期的结果,文本Example有点太远了:

在此输入图像描述

示例: https: //codesandbox.io/s/material-demo-2od20