der*_*rei 1 html css line-breaks pre
我知道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>
Run Code Online (Sandbox Code Playgroud)
我从数据库中获取了文本,所以我无法使用li或其他东西......但我必须保持格式化(空格缩进,换行符,保存在DB中的所有内容).问题是<br>换行符比文本换行换行符高(从css获取其值).有什么方法可以控制它们吗?据我所知,<br>继承它的高度值...但我不从它继承的地方继承它.从当前文本,父级还是浏览器默认设置?
只需删除<br>标签并保持换行符.该pre标签将打破那里有文本换行字符的行:
<pre>Some text
second line of text
third line
some longer text that will get wrapped on another line
</pre>
Run Code Online (Sandbox Code Playgroud)
或者br使用CSS 隐藏标签:
pre br { display: none; }
Run Code Online (Sandbox Code Playgroud)