6

When I press enter in a textarea which has whitespace attribute is set to nowrap through css, it is ineffective. No new line is created. Instread a simple whitespace appears. This is only true in IE8. I Have tried current version of Opera,Chrome and Firefox and I have not encountered such problems. Do you have some solution for this?

Thanks..

I have this:

.gwt-TextArea
{
white-space:nowrap;
}

where gwt-TextArea sets the textarea.

Also, I have tried

.gwt-TextArea
    {
    white-space:pre;
    }

It seems to give the same result.

Aftershock
  • 5,205
  • 4
  • 51
  • 64

4 Answers4

5

This article says Internet Explorer ignores line breaks with white-space: nowrap.

Their fix is to use white-space: pre. Does that get you your desired behavior?

jimyi
  • 30,733
  • 3
  • 38
  • 34
5

So, the solution is, unfortunately, this -
For Internet Explorer 7, any white-space value other than pre will cause this issue.
For Internet Explorer 8, any white-space value other than pre-wrap will cause this issue.

I have not tried Internet Explorer 9, though.
In case this is happening there as well, just create a blank page with (a doctype and) a <textarea>, open it and press F12. In the console ("Scripts" tab), type console.log(document.getElementsByTagName("TEXTAREA")[0].currentStyle.whiteSpace) and simply use the value that is displayed within the output as the value of the white-space property of the <textarea>.

Update

I tried Internet Explorer 11. In emulation modes since Internet Explorer 7 mode, it behaves like Chrome in quirks mode (meaning, only white-space: normal and white-space: nowrap cause this issue). I guess they (unintentionally?) backported some fix to most of the emulation modes.

PhistucK
  • 2,466
  • 1
  • 26
  • 28
  • This issue still exists in Internet Explorer 11, even if you set `white-space` value to `normal` explicitly. – wangkaibule Mar 11 '16 at 00:34
  • @wangkaibule - Chrome ignores new lines if you set it to `normal` or `nowrap`. I guess this is by design. Internet Explorer 11 fixed the rest, though. I updated my answer with data regarding Internet Explorer 11. – PhistucK Mar 12 '16 at 09:40
1

Does it have to be CSS solution? If not, you could assign attribute wrap="off" for textarea.

Pett
  • 11
  • 1
  • I was having inconsistent behavior between IE9 and Chrome 13. Setting the attribute wrap="off" worked the same in both browsers. – jwatts1980 Aug 15 '11 at 07:23
0

The available options (found here: Quirksmode.org), are:

  • normal
  • nowrap, IE5.5+
  • pre, IE6+
  • pre-line IE8
  • pre-wrap IE8

It might be worth using white-space: normal (I don't have IE with which to experiment, but I imagine that normal would be available by default if it's possible to alter the state to abnormal).


Edited, with respect to the OP's comment/response.

Are you using a doctype? (I recommend using <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">)

Assuming that you are, is there any chance you could post a link to a demo-page? Or perhaps post your (x)html and css, to see if there's some manner of style-override, or typo, preventing the css being applied?

David Thomas
  • 249,100
  • 51
  • 377
  • 410
  • 1
    pre-line is not ok, it does not keep spaces and tabs. I tried pre, it does not work. Normal is the wrapped mode, that did not help either. I looked at quirksmode.org. It claims IE8 is fully compatible with respect to pre and nowrap. It does not seem to me so. At least for textareas. – Aftershock Aug 15 '09 at 22:13