JSFiddle - React, Tailwind, and code Playground
by David_Knowles
HTML
<div class="container">
<img class="center-center full-width full-height" src="http://dummyimage.com/600x400/000/fff">
</div>
CSS
* {
box-sizing:border-box;
}
body {
padding: 50px;
background-color: #eee;
}
.container {
height: 80%;
width: 100%;
background-color: pink;
position: relative;
border: 1px solid red;
min-height:300px;
}
.center-center {
position: absolute;
left: 50%;
top: 50%;
-ms-transform: translateY(-50%) translateX(-50%);
-webkit-transform: translateY(-50%) translateX(-50%);
transform: translateY(-50%) translateX(-50%);
}
img {
opacity:0.7;
}
.full-width {
min-width: 100%;
}
.full-height {
min-height: 100%;
}
JavaScript
// Center Image within Parent even if image is larger than parent container