resize CSS property sets whether an element is resizable, and if so, in which directions.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

resize does not apply to the following:

  • Inline elements
  • Block elements for which the overflow property is set to visible

句法

/* Keyword values */
resize: none;
resize: both;
resize: horizontal;
resize: vertical;
resize: block;
resize: inline;
/* Global values */
resize: inherit;
resize: initial;
resize: unset;
					

resize property is specified as a single keyword value from the list below.

none

The element offers no user-controllable method for resizing it.

both

The element displays a mechanism for allowing the user to resize it, which may be resized both horizontally and vertically.

horizontal
The element displays a mechanism for allowing the user to resize it in the horizontal direction.
vertical
The element displays a mechanism for allowing the user to resize it in the vertical direction.
block
The element displays a mechanism for allowing the user to resize it in the block direction (either horizontally or vertically, depending on the writing-mode and direction value).
inline
The element displays a mechanism for allowing the user to resize it in the inline direction (either horizontally or vertically, depending on the writing-mode and direction value).

形式定义

初始值 none
适用于 elements with overflow other than visible , and optionally replaced elements representing images or videos, and iframes
继承 no
计算值 如指定
动画类型 discrete

形式句法

none | both | horizontal | vertical | block | inline
					

范例

Disabling resizability of textareas

In many browsers, <textarea> elements are resizable by default. You may override this behavior with the resize 特性。

HTML

<textarea>Type some text here.</textarea>
					

CSS

textarea {
  resize: none; /* Disables resizability */
}
					

结果

Using resize with arbitrary elements

可以使用 resize property to make any element resizable. In the example below, a resizable <div> contains a resizable paragraph ( <p> element).

HTML

<div class="resizable">
  <p class="resizable">
    This paragraph is resizable in all directions, because
    the CSS `resize` property is set to `both` on this element.
  </p>
</div>
					

CSS

.resizable {
  resize: both;
  overflow: scroll;
  border: 1px solid black;
}
div {
  height: 300px;
  width: 300px;
}
p {
  height: 200px;
  width: 200px;
}
					

结果

规范

规范 状态 注释
CSS Basic User Interface Module Level 3
The definition of 'resize' in that specification.
推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
resize Chrome 完整支持 1 Edge 完整支持 79 Firefox 完整支持 4 IE 不支持 No Opera 完整支持 12.1 Safari 完整支持 3 WebView Android 完整支持 37 Chrome Android 完整支持 18 Firefox Android 完整支持 4 Opera Android 完整支持 14 Safari iOS 完整支持 1 Samsung Internet Android 完整支持 1.0
Support on block level, replaced, table cell, or inline block elements Chrome 完整支持 4 Edge 完整支持 79 Firefox 完整支持 5 注意事项
完整支持 5 注意事项
注意事项 resize doesn't have any effect on <iframe> 。见 bug 680823 )
IE 不支持 No Opera 完整支持 15 Safari 完整支持 4 WebView Android 完整支持 37 Chrome Android 完整支持 18 Firefox Android 完整支持 5 注意事项
完整支持 5 注意事项
注意事项 resize doesn't have any effect on <iframe> 。见 bug 680823 )
Opera Android 完整支持 14 Safari iOS 完整支持 3.2 Samsung Internet Android 完整支持 1.0
Support for flow-relative values block and inline Chrome 不支持 No Edge 不支持 No Firefox 完整支持 63 IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 完整支持 63 Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

见实现注意事项。

另请参阅

元数据

  • 最后修改: