If I have:
#logo {
width: 400px;
height: 200px;
}
then
Load the image as a background for a div.
Instead of:
do
All browsers will crop the part of the image that doesn't fit.
This has several advantages over wrapping it an element whose overflow is hidden:
url(pic) center top;Update: This answer is from before object-fit; you should now probably use object-fit/object-position.
It is still useful for older browsers, for extra properties (such as background-repeat), and for edge cases (For example, workaround Chrome bugs with flexbox and object-position and FF's (former?) issues with grid + autoheight + object-fit. Wrapper divs in grid / flexbox often give... unintuitive results.)