Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > [CSS] how can I show spaces as spaces?

Reply
Thread Tools

[CSS] how can I show spaces as spaces?

 
 
Tomasz Chmielewski
Guest
Posts: n/a
 
      09-05-2009
When I use <pre>, the spaces will be shown as spaces in a rendered page,
i.e.:

<pre>
5
4
3
2
1
0
</pre>


Will be rendered as:

5
4
3
2
1
0

Without <pre>, it would be rendered as:

5
4
3
2
1
0


Which is not what I want.

How can I tell the browser through CSS that I want to render spaces as
spaces? In other words, render this:

<div class="messageBody">
5
4
3
2
1
0
</div>

Like below:

5
4
3
2
1
0



--
Tomasz Chmielewski
http://wpkg.org
 
Reply With Quote
 
 
 
 
Tomasz Chmielewski
Guest
Posts: n/a
 
      09-05-2009
Tomasz Chmielewski wrote:

> How can I tell the browser through CSS that I want to render spaces as
> spaces? In other words, render this:


Replying to myself - something like this should do:

div.messageBody {
white-space: pre;
}



--
Tomasz Chmielewski
http://wpkg.org
 
Reply With Quote
 
 
 
 
dorayme
Guest
Posts: n/a
 
      09-05-2009
In article <h7unh7$6o6$(E-Mail Removed)>,
Tomasz Chmielewski <(E-Mail Removed)> wrote:

> How can I tell the browser through CSS that I want to render spaces as
> spaces? In other words, render this:
>
> <div class="messageBody">
> 5
> 4
> 3
> 2
> 1
> 0
> </div>


Diagonal writing!

<http://dorayme.netweaver.com.au/diagonalWriting.html>

--
dorayme
 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      09-06-2009
Tomasz Chmielewski wrote:

> Tomasz Chmielewski wrote:
>
>> How can I tell the browser through CSS that I want to render spaces
>> as spaces? In other words, render this:

>
> Replying to myself - something like this should do:
>
> div.messageBody {
> white-space: pre;
> }


It cannot be regarded as the correct answer to the question you asked, which
would more correctly be formulated as "how can I make spaces
non-collapsible", since white-space: pre has essential other effects too.

The rule

div.messageBody {
white-space: pre-wrap;
}

would do what you describe in the question quoted: don't collapse a sequence
of spaces to a single space, but otherwise render the text as usual -
specifically, lines would be wrapped normally. The value pre-wrap still has
limited browser support (even on IE 8, you need to be in "standards mode"
for it to work).

But maybe your _real_ question was implicit in the introduction: "When I use
<pre>". Maybe you really wanted to ask "How can get the same effect in CSS
as I get with <pre> in HTML?"

Then your own answer would be the correct one. However, the question arises
why you would do that. Do you really want the text to be rendered as a
normal paragraph, with collapse of spaces and treating any newline in the
source as equivalent to space, when your style sheet is not applied or your
rule is overridden by other (browser, user) style sheets?

I guess this depends on why you would want to have the text displayed as
preformatted. But I cannot see any particular benefit in making it in a less
reliable way (CSS vs. HTML).

--
Yucca, http://www.cs.tut.fi/~jkorpela/

 
Reply With Quote
 
Tomasz Chmielewski
Guest
Posts: n/a
 
      09-06-2009
Jukka K. Korpela wrote:

> I guess this depends on why you would want to have the text displayed as
> preformatted. But I cannot see any particular benefit in making it in a
> less reliable way (CSS vs. HTML).


I have some software which "transforms" received emails into web pages.

Basically, it reads an email and creates a HTML page with very little
modification to the email body: it will add some <br> tags and will
highlight the links, but nothing more than that.


This means that with "normal" HTML rendering, all spaces will not be
shown (if they are not replaced into &nbsp; - and the software I have
doesn't do it), which will "break" emails if someone "centered" anything
carefully with spaces.



I have little control over the software, that's why I want to "show
spaces" with CSS.



--
Tomasz Chmielewski
http://wpkg.org
 
Reply With Quote
 
Tomasz Chmielewski
Guest
Posts: n/a
 
      09-06-2009
dorayme wrote:
> In article <h7unh7$6o6$(E-Mail Removed)>,
> Tomasz Chmielewski <(E-Mail Removed)> wrote:
>
>> How can I tell the browser through CSS that I want to render spaces as
>> spaces? In other words, render this:
>>
>> <div class="messageBody">
>> 5
>> 4
>> 3
>> 2
>> 1
>> 0
>> </div>

>
> Diagonal writing!
>
> <http://dorayme.netweaver.com.au/diagonalWriting.html>


Unfortunately, I don't have much control over HTML code, so I can't do
it this way.


--
Tomasz Chmielewski
http://wpkg.org
 
Reply With Quote
 
Jan C. Faerber
Guest
Posts: n/a
 
      09-06-2009
On Sep 6, 1:54*am, dorayme <(E-Mail Removed)> wrote:

> Diagonal writing!
>
> <http://dorayme.netweaver.com.au/diagonalWriting.html>


Or with '&nbsp;'


<html>
<head>
<title>lazy man</title>
</head>
<body>
<script language="JavaScript">
<!--
var space = '&nbsp;&nbsp;&nbsp;&nbsp;';
for (var x=20;x>0;x--)
{
var z = space;
for (var a=0;a<x;a++)
{
z = z + space;
}
document.writeln(z + 'hi<br>');
}
// -->
</script>
</body>
</html>
 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      09-06-2009
Tomasz Chmielewski wrote:

> I have some software which "transforms" received emails into web
> pages.


I guess the main problems (which you might still be unaware of) are not
technical but more fundamental. Publishing an arbitrary e-mail message
without permissions easily takes you on the wrong side of the law, or at
least into trouble.

> Basically, it reads an email and creates a HTML page with very little
> modification to the email body: it will add some <br> tags and will
> highlight the links, but nothing more than that.


Then it's horrendously wrong. Test it with a message containing
<blink><font size=7 color=red>Goofed!</font></blink>

And how does it handle MIME, for example?

> This means that with "normal" HTML rendering, all spaces will not be
> shown (if they are not replaced into &nbsp; - and the software I have
> doesn't do it), which will "break" emails if someone "centered"
> anything carefully with spaces.


If you wish to consider such issues, then you should probably consider
division into lines as well. Little does it help to preserve spaces
otherwise.

> I have little control over the software, that's why I want to "show
> spaces" with CSS.


No, you need more control over the software, or really some different
software, for the part of the activity that makes sense.

--
Yucca, http://www.cs.tut.fi/~jkorpela/

 
Reply With Quote
 
Jan C. Faerber
Guest
Posts: n/a
 
      09-06-2009
On Sep 6, 1:54*pm, "Jan C. Faerber" <(E-Mail Removed)> wrote:

Or with text:

> <html>
> <head>
> <title>lazy man</title>
> </head>
> <body>
> <script language="JavaScript">

<!--
var b = 'text with 20 letters';
var space = '&nbsp;&nbsp;&nbsp;&nbsp;';
for (var x=19;x>=0;x--)
{
var z = space;
for (var a=0;a<x;a++)
{
z = z + space;
}
document.writeln(z + b.charAt(x) + '<br>');
}
> </script>
> </body>
> </html>


 
Reply With Quote
 
Jan C. Faerber
Guest
Posts: n/a
 
      09-06-2009
On Sep 6, 2:25*pm, "Jan C. Faerber" <(E-Mail Removed)> wrote:
> On Sep 6, 1:54*pm, "Jan C. Faerber" <(E-Mail Removed)> wrote:


Or with text going from the top down to the bottom:

> > <html>
> > <head>
> > <title>lazy man</title>
> > </head>
> > <body>
> > <script language="JavaScript">

<!--
var b = 'text with 20 letters';
var turn = b.charAt(19);
for (var l=1;l<=19;l++)
{
var turn = turn + b.charAt(19-l);
}
var space = '&nbsp;&nbsp;&nbsp;&nbsp;';
for (var x=19;x>=0;x--)
{
var z = space;
for (var a=0;a<x;a++)
{
z = z + space;
}
document.writeln(z + turn.charAt(x) + '<br>');
}
// -->
> > </script>
> > </body>
> > </html>


(in the last posting I forgot the closing
//-->)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
XSD to allow A-Z 0-9 and spaces, but not leading/trailing spaces johkar XML 2 12-10-2009 09:24 AM
how can I show spaces as spaces, part 2 Tomasz Chmielewski HTML 14 09-10-2009 03:54 PM
Re: How to trim a String trailing spaces, but not leading spaces? Roedy Green Java 3 09-14-2008 02:10 AM
Re: How to trim a String trailing spaces, but not leading spaces? John B. Matthews Java 4 09-12-2008 05:28 AM



Advertisments