2

I have this canvas on my webpage, but whenever I load it, whichever way I resize the screen, it always ends up with a scrollbar for the horizontal and vertical axes. How can I fix this? My monitor does have a different aspect ratio, so does that affect it in any way? I can't really give any refernce code as the only time I even mention the width and height is the first time I set the values:

canvas.width = 1280;
canvas.height = 720;

Help would be really appreciated, I'm in a sort of crisis right now XD

EDIT: This is sort of irrelevant, but here's all my code on codepen

4
  • 1
    Have a look at the css overflow property Commented May 20, 2018 at 19:26
  • Wouldn't that just hide some of it? I want to see the whole thing, just in the right space. Commented May 20, 2018 at 19:27
  • Couls you provide the relevant html and css and js in a jsfiddle? That would make helping a lot easier Commented May 20, 2018 at 19:29
  • Make a codepen demo, its easier for us to help you that way. Commented May 20, 2018 at 19:30

2 Answers 2

2

Just add box-sizing:

canvas {
        box-sizing: border-box;
        border: 1px solid black;
        height: 100vh;
        width: 100vw;
}

The reason the scroll bars appear is that the canvas element uses the border that exceeds the window boundaries.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, it fixed it. You're a lifesaver!!
0

Try the vh and vw property of css. Should use your screens vertical height as the default. Should help. Set them to 100.

3 Comments

Nope, didn't work. Even if I set the window's height and width, it still has a little scrollbar.
Consider hiding the scroll bar with css then
That would leave some of the canvas out of the window, making it impossible to see, which is not what I want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.