cross browser nowrap textarea

你说的曾经没有我的故事 提交于 2019-12-06 22:49:43

问题


I'm looking for a cross browser solution that makes textarea :

  • wrap text only on enter
  • scrollbars both hidden, until text overflows

I have tried almost everything can be found in SO...

Failed #1:

textarea{
  white-space:nowrap;
  overflow: auto;
}

does not work in FF

Failed #2:

textarea{
  white-space:nowrap;
  overflow: auto; // or scroll
}
+WRAP=OFF attribute

here I cant hit enter in IE (jsFiddle)

Failed #3:

textarea{
  white-space:pre;
  overflow: auto;
}
+WRAP=OFF attribute

auto line break in IE if I reaches the end


回答1:


All I did was remove your white-space: nowrap; and it works :).

textarea{
overflow: auto;
}
<textarea wrap="off">
Lorem asldm,és améld masémd éasmdá qw3őri2ő3pjm powemfnsd f
dsf lsdmflkms dlkfmsldk mflksdmfk lmsklf
</textarea>



回答2:


<textarea wrap="off"><textarea>



回答3:


You should try white-space: pre;

textarea{
  white-space: pre;
  width: 200px;
  height: 200px
}
<textarea>
Hello World!
Happy New Year Stack Overflow!!
    With Indent
</textarea>



回答4:


overflow-wrap: normal;

Just change the overflow parameter for wrap to normal.



来源:https://stackoverflow.com/questions/14443262/cross-browser-nowrap-textarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!