Q:

How to make parent element the same size as his child which is absolutely positioned to his grandparent?

I have a grandparent div .grandparent with an image element .child-image inside which is absolutely positioned in relation to .grandparent. I want the wrapper element .parent-wrapper (which wraps the image) to have the same width and height as the its child .child-image. Is it possible? I tried almost everything but still can't figure it out.
Here is codepen: https://codepen.io/anon/pen/MRNwoJ?editors=1100

.grandparent {
  height: 650px;
  max-height: calc(100vh - 100px);
  width: 642px;
  position: relative;
  display: inline-block;
  float: left;
  padding: 0;
  margin: 0 0 25px 0;
  background-color: #464646;
  text-align: center;
}

.parent-wrapper {
  height: unset;
  max-height: calc(100vh - 300px);
  background-color: red;
  float: left;
}

.child-image {
  display: block;
  margin: 0 auto;
  min-height: 1px;
  height: auto;
  width: auto;
  max-height: 100%;
  max-width: 100%;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  cursor: unset;
}
<div class="grandparent">
  <div class="parent-wrapper">
    <img class="child-image" src="https://cfl.dropboxstatic.com/static/images/index/rebrand/co_create/desktop/dropbox_digital_desktop_02-vflq-5NiU.jpg">
  </div>
</div>

A:

I have no idea why are you making all this complicated. I have changed the code in a simpler form, hope this is what you want. if you want something else specific please do comment. 

.grandparent {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 650px;
    width: 100%;
    margin: 0 0 25px 0;
    background-color: #464646;
    text-align: center;
  }

  .parent-wrapper {
    display: inline-block;
  }
  
  img {
   max-width: 100%;
  }
<div class="grandparent">
  <div class="parent-wrapper">
    <img class="child-image" src="https://cfl.dropboxstatic.com/static/images/index/rebrand/co_create/desktop/dropbox_digital_desktop_02-vflq-5NiU.jpg">
  </div>
</div>

