Propriedade de ajuste de objeto CSS
Exemplo
Corte as laterais de uma imagem, preservando a proporção, e preencha o espaço:
img.a {
width: 200px;
height:
400px;
object-fit: cover;
}
Definição e uso
A object-fit
propriedade é usada para especificar como um <img> ou <video> deve ser redimensionado para caber em seu contêiner.
Essa propriedade informa ao conteúdo para preencher o contêiner de várias maneiras; como "preservar essa proporção" ou "esticar e ocupar o máximo de espaço possível".
Valor padrão: | ver propriedades individuais |
---|---|
Herdado: | não |
Animavel: | não. Leia sobre animáveis |
Versão: | CSS3 |
Sintaxe JavaScript: | object .style.objectFit="cover" |
Suporte ao navegador
Os números na tabela especificam a primeira versão do navegador que oferece suporte total à propriedade.
Property | |||||
---|---|---|---|---|---|
object-fit | 31.0 | 16.0 | 36.0 | 7.1 | 19.0 |
Sintaxe CSS
object-fit: fill|contain|cover|scale-down|none|initial|inherit;
Valores de propriedade
Value | Description | Try it |
---|---|---|
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 |
Páginas relacionadas
Tutorial CSS: ajuste de objeto CSS
Referência CSS: posição do objeto CSS
Referência HTML DOM: a propriedade objectFit