这个object-fit
属性用于指定如何调整 <img> 或 <video> 的大小以适合其容器。
该属性告诉内容以多种方式填充容器;例如"preserve that aspect ratio" 或"stretch up and take up as much space as possible"。
表中的数字指定完全支持该属性的第一个浏览器版本。
Property | |||||
---|---|---|---|---|---|
object-fit | 31.0 | 16.0 | 36.0 | 7.1 | 19.0 |
object-fit: fill|contain|cover|scale-down|none|initial|inherit;
Value | Description | Demo |
---|---|---|
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 | Demo ❯ |
contain | The replaced content is scaled to maintain its aspect ratio while fitting within the element's content box | Demo ❯ |
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 | Demo ❯ |
none | The replaced content is not resized | Demo ❯ |
scale-down | The content is sized as if none or contain were specified (would result in a smaller concrete object size) | Demo ❯ |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
CSS教程:CSS 对象适配
CSS 参考:CSS 对象位置
HTML DOM 参考:objectFit 属性
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!