JSFiddle - React, Tailwind, and code Playground

HTML

<div class="centerDiv"></div>

CSS

.centerDiv{
    width:300px;
    height:200px;
    border:1px solid red;
    background: #ccc;
}

JavaScript

$(window).resize(function(){

    $('.centerDiv').css({
        position:'absolute',
        left: ($(window).width() - $('.centerDiv').outerWidth())/2,
        top: ($(window).height() - $('.centerDiv').outerHeight())/2
    });

});

// To initially run the function:
$(window).resize();