JSFiddle - React, Tailwind, and code Playground

by acwong

HTML

<div id="outer">
    <div id="inner"></div>    
</div>

CSS

#outer {
    position: relative;
    width: 500px;
    height: 500px;
    border: 2px solid yellow;
}
#inner {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100px;
    height: 100px;
    background-color: red;
}

JavaScript

var inner = document.getElementById("inner");

alert(inner.offsetTop);
alert(inner.offsetLeft);