Retain newlines in HTML but wrap text: possible?

前端 未结 5 2059
再見小時候
再見小時候 2020-12-17 01:14

I came across an interesting problem today. I have a text email I\'m sending from a Web page. I\'m displaying a preview and wanted to put the preview in a fixed font retai

相关标签:
5条回答
  • 2020-12-17 01:49

    Just replace all your hard line breaks with <br/> and put the text into a div with the desired width. You can do the same with spaces: Replace them with &nbsp;.

    Be sure you do this after you escape the special characters into HTML, otherwise the
    are not interpreted but printed on the page.

    0 讨论(0)
  • 2020-12-17 01:53

    Try

    selector {
      word-wrap: break-word; /* IE>=5.5 */
      white-space: pre; /* IE>=6 */
      white-space: -moz-pre-wrap; /* For Fx<=2 */
      white-space: pre-wrap; /* Fx>3, Opera>8, Safari>3*/
    }
    
    0 讨论(0)
  • 2020-12-17 01:57

    create a <pre></pre> tag or use something like
    <p style="width:800px"> .... </p>

    with fixed width, i think text are wrapped

    0 讨论(0)
  • 2020-12-17 02:00

    Try replacing any double spaces with &nbsp;&nbsp; - which should work to make your look of double spaces come through.

    Crack all those new line and hard enters out with <br />.

    Style the text output to make it look like a fixed-width with the font-family:

    font-family:monospace;
    

    You may need to size it up properly, something smaller than the surrounding text, but that will give you the look of a PRE, and what a plain text email will look like.

    Put it all in a DIV with a fixed with and that could be worth a look.

    0 讨论(0)
  • 2020-12-17 02:06

    Maybe you could use a RichTextEditor (such as FreeTextBox) to display the text.

    Set the editor's font to Courier, disable/hide the toolbars, ...

    0 讨论(0)
提交回复
热议问题