console
window.onload = function () {
const box = document.getElementById("box")
const height = box.offsetHeight;
box.setAttribute("style", "--height: " + height + "px");
console.log(height)
}
<label for="checkbox">点我</label>
<input id="checkbox" type="checkbox"/>
<div id="box" class="box" style="--height: 200px">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<div class="test"></div>
.box {
width: 200px;
height: 0;
overflow: hidden;
background: green;
}
#checkbox {
display: none;
}
#checkbox:checked + .box {
height: var(--height);
}