0

Im working on a website where i have to crop images on the left and right side, and center them. I found a solution for this, with this code: http://codepen.io/anon/pen/dXMrWj

<div class='container'>
  <img src='https://source.unsplash.com/category/nature/800x1000/daily'>
</div>

-

body {
  margin: 0; padding: 0;
}

.container {
  width: 40%;
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

img {
    height: 100%;
}

Only it doesn't work in Safari, is presume because the "VH" unit maybe. Does anyone know how to fix this?

Jelle
  • 29
  • 1
  • 8
  • Should not be a `vh` problem: [browser support](https://developer.mozilla.org/en-US/docs/Web/CSS/length#Browser_compatibility) – Randy Jul 05 '16 at 10:27

1 Answers1

1

Adding object-fit: cover; to the img styling seems to fix the problem in Safari and it still looks good in Chrome. Untested in other browsers

http://codepen.io/panchroma/pen/rLwAJd

David Taiaroa
  • 25,157
  • 7
  • 62
  • 50