Objeto de estiloFit Propiedad
Ejemplo
Recorte los lados de una imagen, conservando la relación de aspecto, y rellene el espacio:
document.getElementById("myImg").style.objectFit = "cover";
Definición y uso
La propiedad objectFit se usa para especificar cómo se debe cambiar el tamaño de un <img> o <video> para que se ajuste a su contenedor.
Esta propiedad le dice al contenido que llene el contenedor de varias maneras; como "preservar esa relación de aspecto" o "estirar y ocupar tanto espacio como sea posible"
Compatibilidad con navegador
Los números de la tabla especifican la primera versión del navegador que es totalmente compatible con la propiedad.
Property | |||||
---|---|---|---|---|---|
objectFit | 31.0 | 16.0 | 36.0 | 7.1 | 19.0 |
Sintaxis
Devuelve la propiedad objectFit:
object.style.objectFit
Establezca la propiedad objectFit:
object.style.objectFit = "fill|contain|cover|scale-down|none|initial|inherit"
Valores de propiedad
Value | Description |
---|---|
fill | This is default. The replaced content is sized to fill the element's content box. If necessary, the object will be stretched or squished to fit |
contain | The replaced content is scaled to maintain its aspect ratio while fitting within the element's content box |
cover | The replaced content is sized to maintain its aspect ratio while filling the element's entire content box. The object will be clipped to fit |
none | The replaced content is not resized |
scale-down | The content is sized as if none or contain were specified (would result in a smaller concrete object size) |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Detalles técnicos
Valor por defecto: | llenar |
---|---|
Valor de retorno: | Una cadena, que representa el ajuste de objeto de un elemento. |
Versión CSS | CSS3 |
páginas relacionadas
Tutorial de CSS: ajuste de objetos CSS
Referencia de CSS: propiedad de ajuste de objeto
❮ Objeto de estilo