Centering a fixed/absolutely positioned image

by audetwebdesign

HTML

<div id="fade"></div>
<div id="fullscreen">
    <img src="http://placekitten.com/1000/800" />
</div>

CSS

#fade {
    /* Cover the entire viewport. */
    position: fixed;
    top: 0px;
    right: 0px;
    bottom: 0px;
    left: 0px;
    /* Transparent Background */
    background-color: #000;
    opacity: 0.50;
}
#fullscreen {
    /* Cover the entire viewport. */
    position: fixed;
    top: 0px;
    right: 0px;
    bottom: 0px;
    left: 0px;
}

#fullscreen img {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;

    margin: auto;
    
    /* Limit the size of the image. */
    max-width: 80%;
    max-height: 80%;
}