I am creating a "light box" sort of effect. Without using JavaScript, how can I make the light box resize according to the viewport size so that it always stays in the center of the viewport and occupy 80% of the width and height?
<div class="fullscreen-dim">
    <div class="dialog">
        <img src="http://placehold.it/300x200">
        <a class="close-button" href="#">CLOSE</a>
    </div>
</div>
.fullscreen-dim {
    background-color: rgba(0, 0, 0, 0.7);
    position: fixed;
    top: 0; right: 0;
    width: 100%;
    height: 100%;
}
img {
    width: 100%;
    height: 100%; // how to respect aspect ratio??
}
.dialog { // dialog should auto-size just big enough to wrap image
    padding: 20px; // to create a "border" around the image;
    position: fixed;
    background-color: red;
    left: 50%; top: 50%;
    transform: translateX(-50%) translateY(-50%);
    width: 80%;
    height: 80%;    
}
a {
    position: absolute;
    bottom: 5px; right: 5px;
}
In this method http://jsfiddle.net/3Lohtes9/ , the dialog resizes but the image does not respect aspect ratio.
This problem can also be interpreted as one of the "grandparent div" questions on SO. How can I set the image size with respect to full-screendim and let dialog to auto-size to fit?
EDIT: Instead of enclosing the img in the dialog div, I can achieve a similar visual effect of having the border around the image and still have the image resize accordingly when viewport size changes. However, I have no way to place the close button now. Any advice?
 
     
     
     
    