使用 pre 时奇怪的缩进
Strange indentation when using pre
在 C# 中,我用字符串填充字段。每个字符串都以“\r\n”结尾。然后我使用 Razor 用这些数据填充一个网站:
<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;"
align="left">
@item.Data
</td>
网站输出:
- first line (about 13 additional empty spaces)
- second line
- third line
- fourth line and so on
期望的输出:
- first line
- second line
- third line
- fourth line and so on
我应该提供更多代码吗?
编辑:
HTML:
<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;"
align="left">
firstline
secondline
</td>
解决方法:
实际上,我在 Visual Studio 中的代码女仆扩展在
之后添加了白色 space(这里有很多白色 space)
您的 white-space:pre;
中的 text/code 应该从行首开始(没有制表符或空格)。我在下面给出了一个例子。
<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;"
align="left">
firstline
secondline
</td>
空格是由“格式化的”html 源代码生成的。
您还需要“丑化”html 代码。
之前:
<tr>
<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;" align="left">
firstline
secondline
</td>
</td>
之后:
<tr>
<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;" align="left">firstline
secondline</td>
</tr>
在 C# 中,我用字符串填充字段。每个字符串都以“\r\n”结尾。然后我使用 Razor 用这些数据填充一个网站:
<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;"
align="left">
@item.Data
</td>
网站输出:
- first line (about 13 additional empty spaces)
- second line
- third line
- fourth line and so on
期望的输出:
- first line
- second line
- third line
- fourth line and so on
我应该提供更多代码吗?
编辑:
HTML:
<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;"
align="left">
firstline
secondline
</td>
解决方法: 实际上,我在 Visual Studio 中的代码女仆扩展在
您的 white-space:pre;
中的 text/code 应该从行首开始(没有制表符或空格)。我在下面给出了一个例子。
<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;"
align="left">
firstline
secondline
</td>
空格是由“格式化的”html 源代码生成的。 您还需要“丑化”html 代码。
之前:
<tr>
<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;" align="left">
firstline
secondline
</td>
</td>
之后:
<tr>
<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;" align="left">firstline
secondline</td>
</tr>