How can I find out the height of an HTML block in vmax?
-
Hello, in general, is it possible to somehow find out the block height in vmax units, and not in px?JavaScript Anonymous, Sep 21, 2020
-
const vmax = element => {
const rect = element.getBoundingClientRect();
const denominator = Math.max(innerWidth, innerHeight);
return {
width: (rect.width / denominator) * 100,
height: (rect.height / denominator) * 100
}
};
You just need to addbox-sizing: border-box;
so that the width / height of the box is correctly calculated in CSS.Anonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!