CSS object-fit eigenschap
Voorbeeld
Snijd de zijkanten van een afbeelding af, behoud de beeldverhouding, en vul de ruimte in:
img.a {
width: 200px;
height:
400px;
object-fit: cover;
}
Definitie en gebruik
De object-fit
eigenschap wordt gebruikt om aan te geven hoe een <img> of <video> moet worden aangepast aan de container.
Deze eigenschap vertelt de inhoud om de container op verschillende manieren te vullen; zoals "behoud die beeldverhouding" of "rek uit en neem zoveel mogelijk ruimte in".
Standaardwaarde: | individuele eigenschappen bekijken |
---|---|
geërfd: | Nee |
Animeerbaar: | Nee. Lees over animeren |
Versie: | CSS3 |
JavaScript-syntaxis: | object .style.objectFit="cover" |
Browserondersteuning
De getallen in de tabel geven de eerste browserversie aan die de eigenschap volledig ondersteunt.
Property | |||||
---|---|---|---|---|---|
object-fit | 31.0 | 16.0 | 36.0 | 7.1 | 19.0 |
CSS-syntaxis
object-fit: fill|contain|cover|scale-down|none|initial|inherit;
Eigendomswaarden
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 |
Gerelateerde pagina's
CSS-zelfstudie: CSS-object-fit
CSS-referentie: CSS-objectpositie
HTML DOM-referentie: de eigenschap objectFit