title: how an img or div can be fitted with a container that has vh unit , less than 100%
body: <p>When I set the height of image to 100% it takes 100% of view port not 80%.
  I used overflow:hidden for container that it worked but the image cropped and I couldn't fixed it with any options of img and css.
  I also replaced img tag with div and set background image for it but I got same problem and image cropped with it again.</p>
  
  <p><a href="https://codepen.io/anon/pen/exbMVK" rel="nofollow noreferrer">codepen</a></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.container {
    max-width: 1200px;
    height: 80vh;
    margin: 0 auto;
    background-color: red;
    position: relative;
    overflow: hidden;
  }
  
  .image-container {
    position: absolute;
    right: 0;
    left: 0;
    top: 30%;
    width: 50%;
    height: 100%;
    background-color: blue;
    margin: 0 auto;
  }
  
  img {
    width: 100%;
    height: 100%;
    display: block;
    background-size: cover;
    background-position: center;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container"&gt;
    &lt;div class="image-container"&gt;
      &lt;img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_582,c_limit/phonepicutres-TA.jpg" alt=""&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>