CSS Properties: object-fit and object-postion

CSS has many obscure properties that can can really make a difference with browsers that support them. Two of these are object-fit and object-position.

The benefits of these two properties is that the allow us to determine the portion of an image that will be seen at various widths, so that by using media-queries different portions of the image can be included or priority can be given to which portions are cropped.

Here are some examples of how using these properties can give some control over the image output:

See the Pen MaVmZG by Kirsten Cassidy (@mantismamita) on CodePen.

In the last example Lisa’s face remains in the centre of the image area. By tweaking the image in media queries a single image can be adapted to any allocated space. By using the <picture> element and srcset attribute a great degree of control over the presented image on any given device can be achieved.

Although they are still unsupported in IE, their advantages are best noticed on mobile devices which are largely supported. Screen Shot 2015-10-14 at 11.54.33

The good news is there is a javascript polyfill for those browsers who are not yet there.

Leave a Reply

Your email address will not be published. Required fields are marked *

Click to view allowed tags

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.