I am new to HTML and JS and am trying to code a basic game. However, I keep running into the issue that scroll bars appear, meaning that something is bigger than it should be. I looked into it a bit, and it seems it is the html tag which is too high for the window. I need to know how to fix this.
This is the code I’m using to make it take the whole window (these are the first 3 lines of code):
let canvas = document.getElementById("mainCanvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
3
Answers
I just found out I can put
overflow: hidden;
in the CSS which fixes my problem.If you want your canvas to take up whole space, you could just add this to your canvas properties.
or
What it does is basically occupy the height and width of your viewport in the browser. I hope it helps you 😉
css
css