JSFiddle - React, Tailwind, and code Playground

HTML

<div class="div1">
        <div class="div2">
            fdsfsdffdf
            fdsfdsfsdff
        </div>
    </div>

CSS

.div1{
        width: 500px;height: 500px;
        background-color: blue;
        position: relative;
    }
    .div2{
        position: absolute;
        width: 200px;
        height: 200px;
        background-color: red;
        top: 50%;
        left: 50%;
        margin-left: -100px;   /*此处为width的一半,所以应用此法,元素必须固定宽、高*/
        margin-top: -100px;

    }