JSFiddle - React, Tailwind, and code Playground

HTML

<div class="center"></div>

CSS

.center {
    display:table;
    position:absolute;
    height:300px;
    width:500px;
    background:red;
}

JavaScript

var parentEl = $(window);

function centerPos() {

    $('.center').css({
        'left': parentEl.width() / 2 - $('.center').width() / 2,
            'top': parentEl.height() / 2 - $('.center').height() / 2
    });
}
$(document).ready(centerPos);
$(window).resize(centerPos);