Html 输入字段,换行而不是水平延伸
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3251661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Input Field, wrap text instead of extending horizontally
提问by Xtian
I have an input field, a user will write text inside but when the text is to long it just extends horizontally instead of dropping down vertically.
我有一个输入字段,用户会在里面写文本,但是当文本很长时,它只是水平延伸而不是垂直下降。
I tried:
我试过:
overflow: hidden;
word-wrap: break-word;
and I had no luck. Any other suggestions on how to accomplish this?
我没有运气。关于如何实现这一点的任何其他建议?
采纳答案by Leniel Maccaferri
I think you should use a multiline input field as TextArea:
我认为您应该使用多行输入字段作为 TextArea:
http://htmlhelp.com/reference/html40/forms/textarea.html
http://htmlhelp.com/reference/html40/forms/textarea.html
Sample code:
示例代码:
<textarea rows="10" cols="30"></textarea>
回答by Kyle Clegg
Xtian - You shouldn't have any restriction on where you need to use an <input>
or a <textarea>
. Just give the text area the same name that you would've used for the input and you'll be fine.
Xtian - 您不应该对需要使用 an<input>
或 a 的位置有任何限制<textarea>
。只需为文本区域指定与用于输入的名称相同的名称,就可以了。
For example, I just replaced
例如,我刚刚更换了
<input type="text" name="reply" />
With
和
<textarea rows="1" cols="26" name="reply"></textarea>
Much better now.
现在好多了。