首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我可以用文本"as-is“来做css div吗?

我可以用文本"as-is“来做css div吗?
EN

Stack Overflow用户
提问于 2015-03-02 17:30:22
回答 2查看 84关注 0票数 0

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

代码语言:javascript
复制
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中并保存它吗?当您将所有文本放入HTML页面时,都不会将所有文本放在一起:

代码语言:javascript
复制
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>标签的行为。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-02 17:31:45

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

空格序列被保留,行仅在源和元素中的换行符处中断。

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

票数 2
EN

Stack Overflow用户

发布于 2015-03-02 17:35:46

嗯..。行为类似于<pre>标记,以完成<pre>标记所做的工作。也许是<pre>标签?只是开个玩笑罢了

代码语言:javascript
复制
<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>标记定义预先格式化的文本。阅读更多的这里

有什么理由不能使用这个吗?

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28815926

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档