Jackson Tale
Jackson Tale

Reputation: 25842

How can I auto remove the white space?

I am processing various RSS news items.

In those items, some of them always have various white spaces (like tabs, redundant space, etc) in front within <p></p> or <div></div>.

How can I automatically remove those unnecessary white spaces in the beginning of a paragraph, using pure HTML or CSS?

Upvotes: 0

Views: 4340

Answers (5)

Asmaa3107
Asmaa3107

Reputation: 776

I had same issue I solved it using "white space attribute"

example :

p{
    white-space: normal;
}

Upvotes: 0

talha2k
talha2k

Reputation: 25493

you can use CSS for doing this:

div
{
  white-space:nowrap;
}

or

p
{
  white-space:nowrap;
}

Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a
tag is encountered

Hope this helps.

Upvotes: 1

Artem O.
Artem O.

Reputation: 3487

Unfortunately, you cannot process HTML element with HTML or CSS. You need a JS for this.

Upvotes: 0

Madara&#39;s Ghost
Madara&#39;s Ghost

Reputation: 175098

Not possible. HTML nor CSS are not programming languages, as such, they do not contain the tools to preform string manipulation.

You could do it easily with javascript like so:

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

Will print

This is a string with multiple spaces

Consider this working example

Upvotes: 2

Dennis Traub
Dennis Traub

Reputation: 51694

If using jQuery, there's the jQuery.trim() function

JavaScript doesn't provide a trim function but here's an example how to write it yourself.

Upvotes: 0

Related Questions