我想禁用文本区域的可调整大小属性。

目前,我可以通过单击文本区域的右下角并拖动鼠标来调整文本区域的大小。如何禁用此功能?


当前回答

使用此属性调整大小:无;

textarea {
  resize: none;
}

其他回答

您也可以尝试使用jQuery

$('textarea').css("resize", "none");

您可以像这样简单地禁用textarea属性:

textarea {
    resize: none;
}

要禁用垂直或水平调整大小,请使用

resize: vertical;

or

resize: horizontal;

我发现了两件事:

第一

textarea{resize: none}

这是一个尚未发布的CSS 3,与Firefox 4(及更高版本)、Chrome和Safari兼容。

另一个格式特性是溢出:考虑到dir属性,自动删除右滚动条。

代码和不同的浏览器

基本HTML

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <textarea style="overflow:auto;resize:none" rows="13" cols="20"></textarea>
</body>
</html>

某些浏览器

Internet Explorer 8

Firefox 17.0.1

使用此属性调整大小:无;

textarea {
  resize: none;
}

使用@style,您可以为其设置自定义大小并禁用调整大小功能(resize:none;)。

@Html.TextAreaFor(model => model.YourProperty, new { @style = "width: 90%; height: 180px; resize: none;" })