如何从textarea删除自动换行? [英] How to remove word wrap from textarea?

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

问题描述

我的简单文本区域在文本溢出时没有显示水平条.它换行换行.那么,如何在文本溢出时删除自动换行并显示水平条呢?

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不应该自动换行,但是您可以将wrap ="soft"设置为显式禁用自动换行:

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>

官方不支持"wrap"属性.我从德语SELFHTML页面(英文来源为此处)表示IE 4.0和Netscape 2.0支持它.我还在FF 3.0.7中按预期的方式对其进行了测试.此处的情况已发生变化,SELFHTML现在是一个Wiki,英语源链接已消失.

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.

如果要确保每个浏览器都支持它,则可以使用CSS更改换行行为:

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

使用层叠样式表(CSS),您可以使用 white-space:nowrap;溢出:自动; .因此,wrap属性可以视为已过时.

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.

来自此处(似乎是提供信息的绝佳页面关于textarea).

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

我不确定它何时更改(根据评论,一定是在2014年左右),但是 wrap 现在是HTML5的正式属性,请参见

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天全站免登陆