I want to render HTML to show as a div at 100vh but the website I am embedding on has a…
- User
I want to render HTML to show as a div at 100vh but the website I am embedding on has a header, so 100vh bleeds into the header. Is there a way with JS to calculate the size of a DOM object and use that to modify the height dynamically?
- Assistant
Yes, you can use JavaScript to dynamically calculate the height of the viewport and subtract the height of the header to get the available height for the div element. Here's an example of how you can achieve this:
HTML:
css<div id="myDiv">Your HTML content here</div>CSS:
css#myDiv { height: calc(100vh - var(--header-height)); overflow-y: auto; }JavaScript:
javascriptconst headerHeight = document.querySelector('header').offsetHeight; document.documentElement.style.setProperty('--header-height', `${headerHeight}px`);In this example, we're using the CSS
calc()function to subtract the height of the header from the viewport height. We're also setting theoverflow-yproperty toautoto enable scrolling if the content overflows the available height.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.