CKTIS / CSS
field-sizing — tamaño de los controles según el contenido
La propiedad field-sizing alterna los controles de formulario entre su tamaño preferido predeterminado y un tamaño basado en el contenido. No sustituye las restricciones de dimensiones.
Versión: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Sintaxis
field-sizing: fixed | content;field-sizing se aplica a elementos con un tamaño preferido predeterminado, como textarea. Su valor inicial, fixed, conserva ese tamaño; no significa que las dimensiones queden bloqueadas en píxeles.
content determina el tamaño intrínseco a partir del contenido e ignora el tamaño preferido predeterminado. Con una width fija, un textarea puede ajustar su altura al número de líneas. Las dimensiones explícitas y las restricciones mínimas y máximas siguen siendo relevantes.
La propiedad no se hereda; su animación es discreta. Su definición procede de un borrador del CSSWG. El ejemplo requiere verificación local: no se debe dar por supuesta la compatibilidad del navegador.
Ejemplos
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>field-sizing</title>
<style>
textarea {
display: block;
width: 16em;
font: 16px/1.5 monospace;
}
#content {
field-sizing: content;
}
#fixed {
field-sizing: fixed;
}
</style>
<label for="content">content</label>
<textarea id="content">One
Two
Three
Four</textarea>
<label for="fixed">fixed</label>
<textarea id="fixed">One
Two
Three
Four</textarea>
</html>Resultado
Expected in a supporting browser: the content textarea fits its four lines vertically; the fixed textarea retains its default preferred height. Adding or deleting lines changes the content textarea's height, but not the fixed textarea's height.
El código mostrado y el resultado declarado se verificaron en un entorno aislado mediante el método registrado en la evidencia de verificación de esta versión exacta.