gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 00:24:43 24 4
gpt4 key购买 nike

我正在处理各种 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com