How can I remove the extra height of html5 canvas?

前端 未结 1 1985
日久生厌
日久生厌 2021-01-02 02:39

I was testing html5 canvas element, and wish my canvas to be full screen in the display area. But I found if I set the canvas height to window.innerHeight, the scroll bar wi

相关标签:
1条回答
  • 2021-01-02 03:22

    By default canvas, unlike div, is display: inline; so it gets set to vertical-align: baseline;. You can take either of the following approaches to make things naturally fill the window.innerHeight:

    #canvas {
        background-color: blue;
        vertical-align: top;
    }
    

    Or:

    #canvas {
        background-color: blue;
        display: block;
    }
    
    0 讨论(0)
提交回复
热议问题