Skip to content

Instantly share code, notes, and snippets.

@shu1
Created June 6, 2022 04:55
Show Gist options
  • Save shu1/c95bfeff92f44dae24c64003906c360b to your computer and use it in GitHub Desktop.
Save shu1/c95bfeff92f44dae24c64003906c360b to your computer and use it in GitHub Desktop.
getBoundingClientRect
#div_1 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: red;
}
@media (min-aspect-ratio: 16/9) {
#div_1 {
width: calc(1600vh / 9);
height: 100vh;
}
}
@media (max-aspect-ratio: 16/9) {
#div_1 {
width: 100vw;
height: calc(900vw / 16);
}
}
<div id="div_1"></div>
window.addEventListener('resize', function () {
var rect = div_1.getBoundingClientRect();
div_1.textContent = `${rect.left}, ${rect.top}`;
});
{"name":"getBoundingClientRect","settings":{},"filenames":["index.html","index.css","index.js"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment