Currently, I am working on a drawing app that is designed to be simple and enjoyable. The app's structure consists of:
- Header
- Canvas
- Footer
One challenge I have encountered involves setting the canvas height to occupy the entire window but excluding the heights of the header and footer.
I've attempted various methods such as:
canvas.height = window.height - (document.getElementById("header").offsetHeight + document.getElementById("footer").offsetHeight);
Additionally, I experimented with:
function getHeight(id) {
id = document.getElementById(id);
return id.offsetHeight + id.style.marginTop + id.style.marginBottom;
}
canvas.height = window.height - (getHeight("header") + getHeight("footer"))
Unfortunately, these approaches did not yield the desired outcome. When using id.style.marginTop
, the console returned an empty string despite the margin being defined in the CSS style as margin: 8px 0 8px 0;
.
Is there a way, without relying on jQuery, to retrieve the actual height of an element including its margin?
I suspect we may need to extract individual values from margin: 8px 0 8px 0;
by utilizing id.style.margin
. However, I am uncertain about the exact approach to achieve this separation.