简体   繁体   English

排版字符串不受 Material-UI CardContent 的限制

[英]Typography String does not stay withing bounds of Material-UI CardContent

I have the following CardContent in my React Material-UI我的 React Material-UI 中有以下CardContent

<CardContent className={classes.cardContent}>
  <Typography component="p" className={classes.title} variant="title">
    {this.props.post.title}
  </Typography>
    {this.props.post.photo &&
      (<div className={classes.photo}>
        <img
          className={classes.media}
            src={'/api/posts/photo/'+this.props.post._id}
            />
  </div>)}
  <pre>
    <Typography component="p" className={classes.text}>
      {this.props.post.text}
    </Typography>
  </pre>
</CardContent>

My problem is that if I have long string in {this.props.post.text} the text does not wrap to stay within the bounds of the card.我的问题是,如果我在{this.props.post.text}有长字符串,则文本不会换行以保持在卡片的范围内。 Instead it gets truncated at the edge of the card.相反,它会在卡的边缘被截断。

How can I get this to wrap instead?我怎样才能让它包装呢?

就我而言,我没有使用<pre>我确实使用了whiteSpace:'pre-wrap'

<Typography  variant="body1" component="div" style={{whiteSpace:'pre-wrap'}} dangerouslySetInnerHTML={createMarkup(this.state.formData.About)} />

 

The problem here is that <pre> maitains the initial formatting of the string, so if it was one long line, it will remain that way when it is rendered.这里的问题是<pre>保持字符串的初始格式,所以如果它是一长行,它在呈现时将保持这种状态。 In this case the line was longer than the width of the card.在这种情况下,线长于卡片的宽度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM