html - 如何自动删除空白区域?

标签 html css removing-whitespace

我正在处理各种 RSS 新闻元素。

在这些元素中,其中一些在 <p></p> 的前面总是有各种空白(如制表符、冗余空格等)或 <div></div> .

如何使用纯 HTML 或 CSS 自动删除段落开头那些不必要的空格?

最佳答案

不可能。 HTML 和 CSS 都不是编程语言,因此它们不包含执行字符串操作的工具。

你可以像这样使用 javascript 轻松地做到这一点:

var str = "This is a      string with           multiple spaces";
str = str.replace(/ {2,}/g, " ");
document.write("<pre>" + str + "</pre>");

将打印

This is a string with multiple spaces

Consider this working example

关于html - 如何自动删除空白区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7347651/

相关文章:

javascript - 在 html 页面中以有序的方式显示结果

html - CSS 固定位置干扰自动宽度

haml - 删除 HAML 中的空格

javascript - 使用 javascript Canvas 调整图像大小(顺利)

javascript - iOS 上网页的 div 数量或内存限制?

php - Joomla 3 全局配置缺少 header

javascript - HTML canvas measureText().width 太大

html - 为什么折叠浏览器时顶部会出现这个空白? [ Bootstrap 3]

phpstorm - Phpstorm 将 "Strip trailing spaces on Save"设置为 "All"忽略带有光标的行

java - 在java中用xpath和selenium解析HTML表格数据