Monospace font in IE8 ignores spaces

2.1k views Asked by At

I'm trying to get a monospaced asci table working, as seen here: <pre> tag and css font-family

This works for me on all browsers, except IE8.

On IE8, the spaces all get compressed into one space. (so the columns disappear)

Any ideas on why IE8 is doing this?

Thanks in advance,

Alex

3

There are 3 answers

1
Rob W On BEST ANSWER

Add white-space:pre to your element to preserve white-space characters.

0
Spudley On

HTML default behaviour is to compress multiple white spaces down to a single space, unless explicitly told not to.

The way to tell it not to do this is to use the CSS white-space property. The value you're probably looking for is to set it to white-space:pre;, which will set a element to display all white space without compressing it.

You can of course also use the <pre> tag itself, which has white-space:pre; set by default. Note that this can be overridden in your stylesheets, so if a <pre> tag isn't working, this is probably the reason. (if this is happening, you can use the Developer Tools window to examine the styles being applied to the element)

In addition to white-space:pre;, there are a couple of other values of the white-space property which you can also use, depending on your requirements: pre-wrap and pre-line.

You can find out more about the differences between them, with examples, here: http://www.quirksmode.org/css/whitespace.html

Hope that helps.

0
MuchiProds On

I have tried this and it worked... (perhaps it helps) Then, fix the rest with styles.

<svg width="600" height="150" font-family="monospace"  xml:space="preserve">
<defs>
<style type="text/css">
<![CDATA[ /* ADD CLASSES */
.font{text-anchor: start; font-size: 12px;font-weight: normal; font-family: "DejaVu Sans Mono", sans-serif;white-space: pre-wrap;}
]]>
</style>
</defs>