Object Fit
The replaced content is sized to fill the element s content box.
Object fit. Customizing responsive and pseudo class variants. First let s dig into object fit. The properties object fit and object position are used to specify the size and position of external media inserted into html mainly the images within the tag but also the content of the. Css object fit 属性 实例 对图片进行剪切 保留原始比例 mycode3 type css img a width.
The object fit css property is used to specify how an or should be resized to fit its container and the object position css property is used together with object fit to specify how an or should be positioned with x y coordinates inside its own content box. This property defines how an element such as an img responds to the width and height of its. They give developers control over the content inside an img or a video similar to the way that we can manipulate the content of a background with background position and background size. The object fit css property sets how the content of a replaced element such as an img or video should be resized to fit its container.
Fill this is default. Only responsive variants are generated for object fit utilities. This is the default value which stretches the image to fit the content box regardless of its aspect ratio. Object fit overview from the spec.
The object fit css property is a cool feature that lets you style the content of replaced elements images videos in a way that is similar to the keyword values in background size most importantly cover and contain there is also an object position property that works almost like you guessed it background position. Also generate hover and focus variants. For example this config will. Object fit and object position are my two favourite css properties lately.
If necessary the object will be stretched or squished to fit. The object fit property can have the following values. Together they provide us with the power to manipulate an image or a video and create some magic.