Jump to content

Game canvas gets wrong resize in DIV


Recommended Posts



If game is in <body> then the size is correct:
But when the game is place to <div> then the size is wrong and there are additional spaces around canvas in both sides
How to fix this and remove that space?
body and div style:
body{        background-color: black;    margin: 0;}#gameContainer{           width: 100%;    height: 100%;    position: absolute;     }
Link to comment
Share on other sites

Probably need more information, but if you are doing position: absolute, you might want to do top: 0px; left: 0px; padding: 0px; too


I added this to div style, but the issue still present.


Here the canvas style in div:




You may notice that the canvas has a strange margin parameters.




And here correct canvas in body:



Link to comment
Share on other sites

Oh, seems I find the solution. Just put this code into resize function:

var gameContainer = document.getElementById(game.parent);gameContainer.style.width = window.innerWidth + "px";gameContainer.style.height = window.innerHeight + "px"; 
Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...