如何从textarea中删除单词包装? [英] How remove word wrap from textarea?

查看:123
本文介绍了如何从textarea中删除单词包装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当文本溢出时,我简单的textarea不显示水平条。它为新行包装文本。那么,如何删除wordwrap并在文本溢出时显示水平栏?

解决方案

Textareas默认情况下不应该打包,但您可以设置wrap =soft来明确禁用wrap:

 < textarea name =nowrapcols =30rows = 3wrap =soft>< / textarea> 

编辑:wrap属性没有官方的支持。我从德文SELFHTML页面得到它(英文原文为此处)表示IE 4.0和Netscape 2.0支持它。我也在FF 3.0.7中测试了它的工作原理。这里的情况已经改变,SELFHTML现在是一个wiki,英文源代码链接已经死了。



<编辑2:如果你想确保每个浏览器都支持它,你可以使用CSS来改变包装行为:


使用层叠样式表(CSS),你可以通过
white-space:nowrap获得同样的效果。溢出:自动;
因此,wrap属性可以被认为是过期的。

From here (似乎是一个有关textarea的信息的优秀页面)。



EDIT3:我不确定它何时发生变化(根据评论,一定是在2014年左右),但 wrap 现在是官方的HTML5属性,请参阅 w3schools 。改变了答案以符合这一点。


my simple textarea doesn't show a horizontal bar when text overflows. It wraps text for a new line. So how do I remove wordwrap and display horizontal bar when text overflows?

解决方案

Textareas shouldn't wrap by default, but you can set wrap="soft" to explicitly disable wrap:

<textarea name="nowrap" cols="30" rows="3" wrap="soft"></textarea>

EDIT: The "wrap" attribute is not officially supported. I got it from the german SELFHTML page (an english source is here) that says IE 4.0 and Netscape 2.0 support it. I also tested it in FF 3.0.7 where it works as supposed. Things have changed here, SELFHTML is now a wiki and the english source link is dead.

EDIT2: If you want to be sure every browser supports it, you can use CSS to change wrap behaviour:

Using Cascading Style Sheets (CSS), you can achieve the same effect with white-space: nowrap; overflow: auto;. Thus, the wrap attribute can be regarded as outdated.

From here (seems to be an excellent page with information about textarea).

EDIT3: I'm not sure when it changed (according to the comments, must've been around 2014), but wrap is now an official HTML5 attribute, see w3schools. Changed the answer to match this.

这篇关于如何从textarea中删除单词包装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆