JSFiddle - React, Tailwind, and code Playground

by kuonyuu

HTML

<div class="responsive-container">
    <div class="img-container centerer">
        <img class="centered" src="http://placehold.it/150x200" alt="" />
    </div>
</div>

CSS

.responsive-container {
    position: relative;
    width: 300px;
    height: 300px;
    border: 1px solid black;
}

.img-container {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
}

.centerer {
    text-align:center; /* Align center inline elements */
    font: 0/0 a;       /* Hide the characters like spaces */
}

.centerer:before {
    content: ' ';
    display: inline-block;
    vertical-align: middle;
    height: 100%;
}

.centered {
    vertical-align: middle;
    display: inline-block;
    max-height: 100%;
    max-width: 100%;
}