【问题标题】:Tags inside pre tag adding other formatting前置标签内的标签添加其他格式
【发布时间】:2019-03-29 12:30:42
【问题描述】:

我正在使用pre 标签来显示代码。我想将一些代码显示为绿色。但是当我在我想要绿色的代码周围放置一个<div> 标签时,它还会执行添加换行符、燕子间距等操作。如何让样式改变颜色?

这是我的最小示例。如果我在 html 文件中有此文本;

<pre>Some space <div style="background-color:#e6ffed;">then</div> more text.</pre>

并在chrome中打开它,它呈现为

Some space 
then
 more text.

(根据需要,“then”行是绿色的)。

【问题讨论】:

    标签: html whitespace removing-whitespace pre


    【解决方案1】:

    只需使用&lt;span&gt;,因为它是一个内联元素。

    &lt;div&gt; 本质上是一个块元素,因此它的行为与您在此处看到的一样。

    您可以通过here了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-20
      • 2018-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多