段落预格式后保持正常文本字体

时间:2015-11-15 06:01:47

标签: html css pre

我有以下代码,我试图测试如何在我的网站上使用预格式。包含pre之后,字体会发生变化,并且线条不会断开以适应200px分区。我想保持默认的字体大小,样式和族。 注意:我不想使用溢出方法。   我希望有这样的输出

"Sometimes it is very hard to code but by
 circumstance you find yourself struggling 
to fit in the game .
Awesome feelings come and disappear.
Niggas say this game is for the patient hearts.
 You nigga is this true??
  Nigga love style
 keep in touch with us at any given time"

加上默认文字字体

<html>
    <head>
       <title>Test</title>
    <style>
    {
      pre{
    font-family: monospace;
    text-wrap: unrestricted;
    }
    }
    </style>
    </head>
    <body>
    <div style='width:200px;'>
      <pre>Sometimes it is very hard to code but by circumstance you find yourself struggling to fit in the game .Awesome feelings come and disappear.Niggas say this game is for the patient hesrts .. You nigga is this true??
    Nigga love style
    keep in touch with us at any given time</pre>
    </body>
    </html>

请帮我解决这个问题

2 个答案:

答案 0 :(得分:3)

删除<pre>元素,然后将样式添加到CSS中,如下所示:

<div style='width:200px; white-space: pre-wrap;'>
      Your text here
</div>

答案 1 :(得分:1)

此解决方案是否符合您的需求? <div style="white-space: pre-wrap;">content</div>

我在link

看到了这一点