code>
What is the best way to preserve white space in HTML? We have a lot of pages that bring down data from our database, and the data may have multiple spaces in it. The rendered HTML elements that hold the data vary from anchor tags (<a>), spans (<span>), table rows (<tr>, <td>, etc.
现在最简单的做法是添加一个全局css类,如下所示:
The easiest thing to do right now would be to add a global css class like so:
body a, span, tr, td { white-space: pre; }
我想知道是否有更好的方法来实现这个而不为每个HTML元素分配一个类。
I'm wondering if there is a better way to implement this without assigning a class to each individual HTML element.
推荐答案
我会使用相同的技术,但在需要它的数据类包装内:
I would use the same technique, but inside a data class wrapper where it is needed:
.data a, .data span, .data tr, .data td { white-space: pre; }
b $ b HTML:
HTML:
<div class="data">
....
</div>
这篇关于HTML / CSS - 在某些元素上保留空格的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
|