0

The text in <pre></pre> steps beyond the boundary of its parental <div></div>. How to solve this problem?

It is said that the line lengths in the preformatted text can be shortened, but how to do it?

I have seen

<%# DataBinder.Eval(Container.DataItem, "Comments")
               .ToString().Replace("\n", "<br />") %>

Is it c#? I am a PHP programmer.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Steven
  • 24,410
  • 42
  • 108
  • 130

2 Answers2

2

You can use CSS to make the text wrap:

pre {
 white-space: pre-wrap;       /* css-3 */
 white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
 white-space: -pre-wrap;      /* Opera 4-6 */
 white-space: -o-pre-wrap;    /* Opera 7 */
 word-wrap: break-word;       /* Internet Explorer 5.5+ */
}

If you don't want the text formatting changed at all, this CSS will use scrollbars to make all of the text viewable anyway:

pre {
  width: 100%;
  overflow: auto;
}
jonthornton
  • 329
  • 1
  • 4
1

Try adding CSS:

pre {
  width: 100%;
  overflow: auto;
}
Lukman
  • 18,462
  • 6
  • 56
  • 66