HTML / CSS - 在某些元素上保留空格的最佳实践? [英] HTML/CSS - Best practice for preserving white space on certain elements?

查看:127
本文介绍了HTML / CSS - 在某些元素上保留空格的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML中保留空白区域的最佳方式是什么? 我们有很多页面从数据库中删除数据,并且数据可能有多个空格。保存数据的呈现的HTML元素根据锚标签),跨度(),表行(, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆