Is there a way to set a maximum height for a div containing an image and hide the parts of the image that exceed this height, while keeping it centered vertically inside the div? For example, if the browser width is 1200px and the image aspect ratio is 4:3, the image should display at (1200x900)px. However, if we want to crop the height to 300px and center it vertically, the image should be positioned at -300px inside the div.
This may require JavaScript, but I'm curious if there's a CSS solution as well. Thanks in advance!