我可以用文本 "as-is" 制作 css div 吗?

Can I make a css div with text "as-is"?

假设我在 foo.html 文件中有这样的文本:

All the World's a Stage

All the world's a stage,
And all the men and women merely players;
They have their exits and their entrances,
And one man in his time plays many parts,

His acts being seven ages. At first, the infant,
Mewling and puking in the nurse's arms.
Then the whining schoolboy, with his satchel

And shining morning face, creeping like snail
Unwillingly to school. And then the lover,
Sighing like furnace, with a woeful ballad
Made to his mistress' eyebrow.

注意空格和换行符。我可以将它放入 div 并保留 css 吗?而不是将所有文本放在一起,就像您放入 HTML 页面时那样:

All the World's a Stage All the world's a stage, And all the men and women merely players; They have their exits and their entrances, And one man in his time plays many parts, His acts being seven ages. At first, the infant, Mewling and puking in the nurse's arms. Then the whining schoolboy, with his satchel And shining morning face, creeping like snail Unwillingly to school. And then the lover, Sighing like furnace, with a woeful ballad Made to his mistress' eyebrow.

我想要的是非常接近 <pre> 标签的行为,我想。

white-space: pre 应用到 div 元素上。

Sequences of whitespace are preserved, lines are only broken at newline characters in the source and at <br> elements.

文档:https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

Hmm.. 行为类似于 <pre> 标签,来完成 <pre> 标签所做的工作。也许是 <pre> 标签? 开玩笑的讽刺

<pre>
All the World's a Stage

All the world's a stage,
And all the men and women merely players;
They have their exits and their entrances,
And one man in his time plays many parts,

His acts being seven ages. At first, the infant,
Mewling and puking in the nurse's arms.
Then the whining schoolboy, with his satchel

And shining morning face, creeping like snail
Unwillingly to school. And then the lover,
Sighing like furnace, with a woeful ballad
Made to his mistress' eyebrow.
</pre>

<pre>标签定义预格式化文本。阅读更多 here.

你有什么理由不能使用它吗?