MUI:避免排版组件之间的换行

IT技术 reactjs material-ui
2021-05-14 17:51:03

我想对我的文本应用两个不同的 Typography 标签,但我不想在它们之间换行。

这就是我所拥有的:

<Typography variant="title" color="inherit" noWrap>
  Project:
</Typography>
<Typography variant="subheading" color="inherit" noWrap>
  Example
</Typography>

这是它的样子(带换行符):

在此处输入图片说明

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

如何删除换行符?

2个回答

将它们包装在 display:flex 中,它将连续显示。

<div style={{display:"flex"}}>
  <Typography variant="title" color="inherit" noWrap>
     Project:
  </Typography>
  <Typography variant="subheading" color="inherit" noWrap>
       Example
  </Typography>
</div>

代码编辑

编辑:您可以使用style={{marginLeft:10}}onExample在两者之间提供间距。如果你想垂直对齐他们,给flexDirection:'column'styleProject

在版本 4.x 上使用 display prop

<Typography variant="h1" color="inherit" display="inline">
  Project:
</Typography>
<Typography variant="subtitle1" color="inherit" display="inline">
  Example
</Typography>

在版本 < 4.x 上使用 inline prop

<Typography variant="title" color="inherit" inline>
  Project:
</Typography>
<Typography variant="subheading" color="inherit" inline>
  Example
</Typography>

https://material-ui.com/api/typography/