JSFiddle - React, Tailwind, and code Playground
HTML
<div class="keepincenter"></div>
CSS
.keepincenter{
position:absolute;
width:100px;
height:50px;
background-color:#ffe400;
}
JavaScript
function keep_div_centered(){
window_height = $(window).height();
window_width = $(window).width();
obj_height = $('.keepincenter').height();
obj_width = $('.keepincenter').width();
$('.keepincenter').css('top',(window_height/2)-(obj_height/2)).css('left',(window_width/2)-(obj_width/2))
}
keep_div_centered();
$(window).resize(function(){
keep_div_centered();
})