Vlastnost přizpůsobení objektu CSS
Příklad
Ořízněte strany obrázku při zachování poměru stran a vyplňte prostor:
img.a {
width: 200px;
height:
400px;
object-fit: cover;
}
Definice a použití
Tato object-fit
vlastnost se používá k určení, jak má být velikost <img> nebo <video> změněna, aby se vešla do kontejneru.
Tato vlastnost říká obsahu, aby naplnil kontejner různými způsoby; jako například „zachovat tento poměr stran“ nebo „roztáhnout a zabrat co nejvíce místa“.
Výchozí hodnota: | viz jednotlivé vlastnosti |
---|---|
Zděděno: | Ne |
Animovatelné: | Ne. Přečtěte si o tématu Animable |
Verze: | CSS3 |
Syntaxe JavaScriptu: | objekt .style.objectFit="cover" |
Podpora prohlížeče
Čísla v tabulce určují první verzi prohlížeče, která plně podporuje vlastnost.
Property | |||||
---|---|---|---|---|---|
object-fit | 31.0 | 16.0 | 36.0 | 7.1 | 19.0 |
Syntaxe CSS
object-fit: fill|contain|cover|scale-down|none|initial|inherit;
Hodnoty vlastností
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 |
Související stránky
CSS tutoriál: CSS object-fit
CSS reference: CSS object-position
HTML DOM reference: Vlastnost objectFit