如何去除html预格式化文本前后的空行?
How to remove the blank lines before and after html pre-formatted text?
我想在html文本中插入预格式化文本,但是渲染器坚持要在预格式化文本前后添加空行。例如,这个 html 代码:
<html>
<body>
Before text
<pre>
Line 1: Pre-formatted text
Line 2: Pre-formatted text
</pre>
After text
</body>
</html>
此输出结果:
Before text Line 1: Pre-formatted text
Line 2: Pre-formatted text
After text
有什么方法可以去掉开头和结尾的空白行吗?如果我想要它们,我可以自己把它们放进去!
评论中可能重复的问题有很多建议。对我有用的解决方案是将 <pre>
替换为 <pre style="margin:0">
,并在 pre-formatted 文本之外添加 <br>
以根据需要进行补偿。
我想在html文本中插入预格式化文本,但是渲染器坚持要在预格式化文本前后添加空行。例如,这个 html 代码:
<html>
<body>
Before text
<pre>
Line 1: Pre-formatted text
Line 2: Pre-formatted text
</pre>
After text
</body>
</html>
此输出结果:
Before textLine 1: Pre-formatted text Line 2: Pre-formatted textAfter text
有什么方法可以去掉开头和结尾的空白行吗?如果我想要它们,我可以自己把它们放进去!
评论中可能重复的问题有很多建议。对我有用的解决方案是将 <pre>
替换为 <pre style="margin:0">
,并在 pre-formatted 文本之外添加 <br>
以根据需要进行补偿。