I want to set the position to a div depending on its own height which can be different depending on the content.
This is the structure:
HTML
<div class="wrapper">
Content
</div>
CSS:
:root {
--height: x;
}
.wrappper {
height: auto;
top: calc(100vh - var(--height));
}
2
Answers
To change a CSS variable (
--height
) in JavaScript, you can use:Here is a small example where we change a CSS variable (
--width
) on a button click:.clientHeight
gives you height of the object. I’m just assigning that to the CSS variable.