Problem
I have a user image that I want to scale up and down using the window so that the height is always 100% and the image remains centered.
Example 1
This example scales as the window resizes, but the height does not remain at 100% and therefore is cropped at the bottom.
.user {
width: 100%;
height: 100%;
object-fit: cover;
object-position: 50% 0%;
}
CodePen Example 1
Example 2
This example works great, in addition, when the width of the browser window is less than the width of the image, the right side is cropped.
I want the image to be cropped, but I want the right and left sides to be cropped the same way.
.user {
object-position: center;
display: block;
height: 100%;
margin-left: auto;
margin-right: auto;
}
CodePen 2 Example
Visual example
Here is an example of how I want the images to display when the browser is scaled horizontally / vertically.
