JSFiddle - React, Tailwind, and code Playground
HTML
<div class="absoluteCenter">
Content of DIV<br><br><br><br><br>Adds scrollbar when window is resized.
</div>
CSS
.absoluteCenter {
/* Must manually set width/height */
width:200px;
height:150px;
outline:1px solid orange;
/* The magic centering code */
margin:auto;
position:absolute;
top:0;bottom:0; /* Aligns Vertically - Remove for Horizontal Only */
left:0;right:0; /* Aligns Horizontally - Remove for Vertical Only */
/* Prevent div from overflowing main window */
max-width:100%;
max-height:100%;
overflow:auto;
}
/* IE 7 and Below */
:first-child+html .absoluteCenter,
* html .absoluteCenter {
/* Place code here to override all above values, and add IE friendly centering */
}