Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

css - What characters allow white-space: pre-wrap to wrap?

I was surprised to find that my white-space: pre-wrap; text is wrapping at > and " characters. I thought it would only wrap at new lines, -, and after one or more spaces.

Here is a fiddle.

It wraps after ", before <. It also wraps after >, before <.

I can't find anything in the spec that says what characters allow wrapping. It only says "Lines are broken at preserved newline characters, and as necessary to fill line boxes.".

question from:https://stackoverflow.com/questions/66058028/what-characters-allow-white-space-pre-wrap-to-wrap

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The same characters which cause wrapping normally will also cause wrapping with white-space: pre-wrap;, with the addition that newlines in the text will also cause newlines in the output.

Try removing white-space: pre-wrap; in your example and you will see that the only change is that there are no longer any blank lines. Otherwise the wrapping behaviour is the same.

See: https://drafts.csswg.org/css-text/#valdef-white-space-pre-wrap

pre-wrap: Like 'pre', this value preserves white space; but like 'normal', it allows wrapping.

For more details about when wrapping can occur normally, see: https://drafts.csswg.org/css-text/#line-breaking


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...