html - 用 pre 手动包装

标签 html css

我正在尝试设计一个页面来显示电子邮件。我在 pre 中有这样的东西,带有 white-space: pre:

>> Donec tincidunt lobortis orci, a cursus dui ullamcorper
>> vel. Praesent vel enim et lectus aliquet laoreet. In tempus
>> sodales.

现在,当 screen-y 太小而溢出时,我不想使用 overflow: auto。相反,我希望它像这样自动换行:

>> Donec tincidunt lobortis orci, a cursus
>> dui ullamcorper vel. Praesent vel enim
>> et lectus aliquet laoreet. In tempus
>> sodales.

如果我能够选择页面中的文本并将其原封不动地复制到电子邮件中,我不介意使用 :before

好吧,让我们先尝试解决一个更简单的问题:假设每行前面没有“>>”前缀。我可以使用 white-space: normal,但是当我复制文本时,我得到一行没有换行符,这是不可取的。那么,如何让我的浏览器换行而不失去在显示时用换行符复制它的能力?

最佳答案

你可以使用:

pre {
 white-space: pre-wrap;      
 white-space: -moz-pre-wrap;  /* Mozilla */
word-wrap: break-word;       /* Internet Explorer */
}

但是它把 >> 当作一颗子弹来处理...... fiddle here

关于html - 用 pre 手动包装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15201612/

相关文章:

html - 如何在 css/html 中放置与窗口浏览器相关的对象?

jquery - 在表 td 上添加多个类

javascript - 如何防止具有更高 z-index 的 html 元素捕获事件

html - 控制元素 html 和 css 的尺寸

html - 需要一些 CSS 字体声明的解释

javascript - 跨度中的 onDblClick 不起作用

html - 将剪辑路径位置移动到鼠标光标

javascript - 使用 animate.css - jQuery 使用多个按钮切换多个 div

html - 按钮处于事件状态的 Bootstrap Navbar - 我无法清除它

html - 控制单词之间的断点