How can I make the canvas item to fill the browser?

Viewed 22

I set the canvas's size in js:

const cv = document.getElementById("cv");
cv.width = innerWidth;
cv.height = innerHeight;

However, there are scroll bars apeared. How can I deal with it? (without using overflow: hidden)

1 Answers

Using overflow: hidden is the correct and easiest code to place in your CSS.

#cv {
  overflow: hidden;
}

This will remove the scrollbars.


However, if you want to avoid that code, you can set padding and margin to 0, which will more or less have the same effect.

#cv {
  padding: 0;
  margin: 0;
}

This will also remove the scrollbars, kind of like overflow: hidden.

Related