--- title: resize slug: Web/CSS/resize tags: - resize - 调整大小 translation_of: Web/CSS/resize ---
resize
CSS 属性允许你控制一个元素的可调整大小性。
{{cssinfo}}
/* Keyword values */ resize: none; resize: both; resize: horizontal; resize: vertical; resize: block; resize: inline; /* Global values */ resize: inherit; resize: initial; resize: unset;
none
both
horizontal
vertical
block
{{experimental_inline}}inline
{{experimental_inline}}visible
,那么resize
属性对该元素无效。{{HTMLElement("textarea")}} 元素在{{gecko("2.0")}} (Firefox 4)中默认是可以进行缩放的. 你可以通过下面的CSS代码来重写这种行为:
textarea.example { resize: none; /* disables resizability */ }
<textarea class="example">Type some text here.</textarea>
{{EmbedLiveSample("Disabling_resizability_of_textareas","200","100")}}
You can use the resize property to make any element resizable. In the example below, a resizable {{HTMLElement("div")}} box contains a resizable paragraph ({{HTMLElement("p")}} element):
.resizable { resize: both; overflow: scroll; border: 1px solid black; } div { height: 300px; width: 300px; } p { height: 200px; width: 200px; }
<div class="resizable"> <p class="resizable"> This paragraph is resizable, because the CSS resize property is set to 'both' on this element. </p> </div>
{{EmbedLiveSample("Using_resize_with_arbitrary_elements","450","450")}}
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS Logical Properties', '#resize', 'resize')}} | {{Spec2('CSS Logical Properties')}} | Adds the values block and inline . |
{{SpecName('CSS3 Basic UI', '#resize', 'resize')}} | {{Spec2('CSS3 Basic UI')}} | Initial definition |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support (on {{HTMLElement("textarea")}}) | 1.0 | {{CompatGeckoDesktop("2.0")}}{{property_prefix("-moz")}} | {{CompatNo}} | 12.1 | 3.0 (522) |
On any block-level and replaced element, table cell, and inline block element (unless {{cssxref("overflow")}} is visible ) |
4.0 | {{CompatGeckoDesktop("5.0")}}[1] | {{CompatNo}} | 15 | 4.0 |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support (on {{HTMLElement("textarea")}}) | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
On any block-level and replaced element, table cell, and inline block element (unless {{cssxref("overflow")}} is visible ) |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
[1] resize
doesn't have any effect on {{HTMLElement("iframe")}} (cf. {{bug(680823)}})