I came across an interesting problem today. I have a text email I'm sending from a Web page. I'm displalying a preview and wanted to put the preview in a fixed font retaining the white space since that's the way the plaintext email will appear.
Basically I want something that'll act like Notepad: the newlines will signal a newline but the text will otherwise wrap to fit inside it's container.
Unfortunately this is proving difficult unless I'm missing something really obvious. I've tried:
CSS white-space: pre. This retains white space but doesn't wrap lines of text so they go out the borders on long lines;
Styling a textarea element to be read only with no border so it basically apepars like a div. The problem here is that IE doesn't like 100% heights on textareas in strict mode. Bizarrely it's OK with them in quirks mode but that's not an option for me.
CSS white-space: prewrap. This is CSS 2.1 so probably not widely supported (I'm happy if its IE7 and FF3 though; I don't care about IE6 for this as its an admin function and noone will be running IE6 that will use this page).
Any other suggestions? Can this really be that hard?
edit: can't comment so more info. Yes atm I am using font Courier New (ie fixed width) and using a regex on the serverside to replace the newlines with <br
> tags but now I need to edit the content and it just strikes me as awkward that you need to strip out and add the <br
>s to make it work.
is there no better way?