在 Safari 中隐藏文本区大小调整句柄

我在应用程序中使用 textarea 组件,并动态地控制它们的高度。当用户键入时,只要有足够的文本,高度就会增加。这在 IE、 Firefox 和 Safari 上都可以很好地工作。

然而,在 Safari 中,右下角有一个“句柄”工具,允许用户通过点击和拖动来调整文本区域的大小。我还注意到了 stackoverflow 的 Ask a questions 页面中的 texttarea 存在这个问题。这个工具令人困惑,基本上就是在妨碍我们。

那么,有没有办法隐藏这个调整大小的手柄呢?

(我不确定“处理”这个词是否合适,但我想不出更好的词了。)

59051 次浏览

You can override the resize behaviour with CSS:

textarea
{
resize: none;
}

or just simply

<textarea style="resize: none;">TEXT TEXT TEXT</textarea>

Valid properties are: both, horizontal, vertical, none

the safari max-height max-width opportunity also works in firefox 4.0 (b3pre). good example here by the way: http://www.alanedwardes.com/posts/safari-and-resizable-textboxes/

Use the following CSS rule to disable this behavior for all TextArea elements:

textarea {
resize: none;
}

If you want to disable it for some (but not all) TextArea elements, you have a couple of options (thanks to this page).

To disable a specific TextArea with the name attribute set to foo (i.e., <TextArea name="foo"></TextArea>):

textarea[name=foo] {
resize: none;
}

Or, using an ID (i.e., <TextArea id="foo"></TextArea>):

#foo {
resize: none;
}

Note that this is only relevant for WebKit-based browsers (i.e., Safari and Chrome), which add the resize handle to TextArea controls.

You can simply override the resize behavior with CSS:

textarea
{
resize: none;
}