JSFiddle - React, Tailwind, and code Playground
by Gustavo Carvalho
HTML
<div class="centralizer popup">
<div class="dragger"></div>
<h1>Abra seu console.</h1>
</div>
CSS
body {
background:#ccc;
}
h1 {
text-align:center;
}
.centralizer {
position:absolute;
/*fixed works too*/
top:50%;
left:50%;
width:352px;
/*can be anything you want, even calc() */
height:180px;
/*can be anything you want, even calc() */
overflow:auto;
/*this puts scrollers if the content inside this element is bigger then the element itself, you can remove if you want */
/*Here the magic begins*/
-webkit-transform: translateY(-50%) translateX(-50%);
-moz-transform: translateY(-50%) translateX(-50%);
-ms-transform: translateY(-50%) translateX(-50%);
transform: translateY(-50%) translateX(-50%);
}
.big-box {
background:yellow;
width:100%;
height:10px;
}
.popup {
background:white;
box-shadow:0 0 0 2px rgba(0, 0, 0, 0.1), 0 0 15px rgba(0, 0, 0, 0.3);
border-radius:3px;
}
.dragger {
background:#eee;
height:35px;
border-radius:3px 3px 0 0;
border-bottom:1px solid #ccc;
}
JavaScript
var popup = document.querySelector('.popup');
var rect = popup.getBoundingClientRect();
console.log("----------");
console.log("getBoundingClientRect(): \n" + "y: " + rect.top + "\nx: " + rect.left);
console.log("offset: \n" + "y: " + popup.offsetTop + "\nx: " + popup.offsetLeft);