JSFiddle - React, Tailwind, and code Playground

by Pankaj Kargirwar

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    body {
      margin: 0;
      padding: 0;
    }

    .element {
      width: 100px;
      height: 100px;
      background-color: red;
      margin-top: 200px;
    }
  </style>
</head>
<body>

<div class="element" id="targetElement"></div>

<script>
  // Get the element by its ID
  const targetElement = document.getElementById('targetElement');

  // Get the bounding box of the element
  const boundingBox = targetElement.getBoundingClientRect();

  // Calculate available vertical space
  const viewportHeight = window.innerHeight;
  const availableSpace = viewportHeight - boundingBox.top;

  // Log the available vertical space
  console.log('Available vertical space:', availableSpace);
</script>

</body>
</html>