我可以用“原样”制作带有文字的css div吗?

时间:2015-03-02 17:30:23

标签: html css text-alignment

假设我在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>标签的行为,我认为。

2 个答案:

答案 0 :(得分:2)

white-space: pre应用于div元素。

  

保留空白的序列,仅在源中的换行符处以及&lt; br&gt;处断行。元件。

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

答案 1 :(得分:-2)

嗯......像<pre>标记这样的行为来执行<pre>标记所做的工作。可能是<pre>代码? 只与讽刺开玩笑

&#13;
&#13;
<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>
&#13;
&#13;
&#13;

<pre>标记定义了预先格式化的文本。阅读更多here

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