Centering a canvas

后端 未结 11 1438
野的像风
野的像风 2021-01-30 10:00

How do I markup a page with an HTML5 canvas such that the canvas

  1. Takes up 80% of the width

  2. Has a corresponding pixel h

11条回答
  •  迷失自我
    2021-01-30 11:02

    As to the CSS suggestion:

    #myCanvas { 
     width: 100%;
     height: 100%;
    }
    

    By the standard, CSS does not size the canvas coordinate system, it scales the content. In Chrome, the CSS mentioned will scale the canvas up or down to fit the browser's layout. In the typical case where the coordinate system is smaller than the browser's dimensions in pixels, this effectively lowers the resolution of your drawing. It most likely results in non-proportional drawing as well.

提交回复
热议问题