Centering a canvas

后端 未结 11 1531
野的像风
野的像风 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 10:58

    Wrapping it with div should work. I tested it in Firefox, Chrome on Fedora 13 (demo).

    #content {
       width: 95%;
       height: 95%;
       margin: auto;
    }
    
    #myCanvas {
       width: 100%;
       height: 100%;
       border: 1px solid black;
    }
    

    And the canvas should be enclosed in tag

    Your browser doesn't support canvas tag

    Let me know if it works. Cheers.

提交回复
热议问题