【问题标题】:Display text in new line - HTML, CSS在新行中显示文本 - HTML、CSS
【发布时间】:2016-12-19 12:52:26
【问题描述】:

我想在 HTML 上显示格式化文本,文本字符串来自数据库。文本显示在 <div class="col-xs-12"> 中,在 div 中我有 <pre> 标记。

如果文本大小超过屏幕,它会超出屏幕截图中显示的 div 宽度。如果没有更多宽度,我想换行并开始新行以显示剩余文本。谢谢。

【问题讨论】:

  • pre{white-space:normal;}

标签: javascript jquery html css


【解决方案1】:

你应该添加:

pre {
   white-space: pre-wrap;       /* Since CSS 2.1 */
   white-space: -moz-pre-wrap;  /* Mozilla */
   white-space: -pre-wrap;      /* Opera 4-6 */
   white-space: -o-pre-wrap;    /* Opera 7 */
   word-wrap: break-word;       /* Internet Explorer */
}

到你的CSS。

【讨论】:

    【解决方案2】:

    不要使用<pre>,而是使用段落标签<p> some text </p>或使用<p> <pre> some text </pre></p>

    在 CSS 中

    p{
       white-space: pre-wrap;    
       word-wrap: break-word; 
    }
    

    【讨论】:

      【解决方案3】:

      在您的样式中添加以下 css:

      pre {
        white-space: pre-wrap;
      }
      

      pre {
        white-space: pre-wrap;
      }
      <pre>Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... Long text here... </pre>

      【讨论】:

        【解决方案4】:

        试试这个:

        CSS:

        pre{
          display:block;
          word-wrap: break-word;
        }
        

        【讨论】:

          猜你喜欢
          • 2015-01-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-01-20
          • 1970-01-01
          相关资源
          最近更新 更多