我有一个变量文本,有时包含纯文本,有时包含代码,有时包含表格。
我想尽量减少数据库中的HTML标签,所以我没有pre
在table
和中使用标签,text
只在代码中使用(其他两种情况不需要空间保留)。
现在我陷入了一个问题,tables
我的数据正在通过nl2br
它导致我的源代码中的以下输出。
<table><br />
<thead><br />
<tr><br />
<th>Operator</th><br />
<th>Left</th><br />
<th>Right</th><br />
<th>Remark</th><br />
</tr><br />
</thead><br />
<tbody><br />
<tr><br />
<td>/</td><br />
<td>10</td><br />
<td>5 or 5 / 2 / 1</td><br />
<td>Left operand is unambiguous, right is not</td><br />
</tr><br />
<tr><br />
<td>/</td><br />
<td>5 or 10 / 5</td><br />
<td>2 or 2 / 1<td><br />
<td>Both left and right are ambiguous</td><br />
</tr><br />
<tr><br />
<td>/</td><br />
<td>2 or 10 / 5 / 2</td><br />
<td>1</td><br />
<td>Right operand is unambiguous and left is not</td><br />
</tr><br />
</tbody><br />
</table><br />
但是在 chrome 开发人员的工具中,它显示出与此不同的东西。
</p><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>
<table class="rembr">
<thead>
<tr>
<th>Operator</th>
<th>Left</th>
<th>Right</th>
<th>Remark</th>
</tr>
</thead>
<tbody>
<tr>
<td>/</td>
<td>10</td>
<td>5 or 5 / 2 / 1</td>
<td>Left operand is unambiguous, right is not</td>
</tr>
<tr>
<td>/</td>
<td>5 or 10 / 5</td>
<td>2 or 2 / 1</td><td>
</td><td>Both left and right are ambiguous</td>
</tr>
<tr>
<td>/</td>
<td>2 or 10 / 5 / 2</td>
<td>1</td>
<td>Right operand is unambiguous and left is not</td>
</tr>
</tbody>
</table><br>
我不明白这种行为为什么同一页面的输出不同。
好吧,现在,我想知道如何在nl2br
没有br
after 每个table
标签的情况下使用 table标签?
经过几天的谷歌搜索,我找到了一个完美的解决方案。pre-wrap
.
它将保留空格和新行,但在文本溢出时换行。
所以,
div{
white-space: pre-wrap;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句