我知道在 stackoverflow 上有很多“类似”的问题,但没有一个能解决我的难题。
代码是这样的:
------------CSS--------------
pre{
white-space : pre-wrap;
line-height:75%;
}
-----------HTML--------------
<pre>Some text<br>
second line of text<br>
third line<br>
some longer text that will get wrapped on another line</pre>
我从数据库中获取文本,所以我不能使用 li
或其他东西......但我必须保留格式(空格缩进,换行符,一切都保存在数据库中)。问题是 <br>
换行符比 text-wrap 换行符(它的值来自 css)高。有什么办法控制他们两个?据我了解,<br>
继承了它的高度值……但我不知道它是从哪里继承的。来自当前文本,来自父级,来自浏览器默认设置?
最佳答案
只需删除 <br>
标签并保留换行符。 pre
标记将在文本中有换行符的地方换行:
<pre>Some text
second line of text
third line
some longer text that will get wrapped on another line
</pre>
或者隐藏br
使用 CSS 的标签:
pre br { display: none; }
关于html行高问题; <br> 与 CSS 行高对比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19895953/