reset
- the display property to block
const canvas = document.querySelector('#canvas')
const viewportWidth = window.innerWidth
const viewportHeight = window.innerHeight
if (canvas.getContext) {
const context = canvas.getContext('2d')
context.fillStyle = '#222'
context.fillRect(0, 0, viewportWidth, viewportHeight)
}
html,
body,
canvas {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
box-sizing: border-box;
}
canvas {
display: block
}
<canvas id="canvas" resize="true">
Your browser does not support HTML Canvas.
To view this page, use a browser that supports HTML Canvas.
</canvas>
const canvas = document.querySelector('#canvas')
const viewportWidth = window.innerWidth
const viewportHeight = window.innerHeight
if (canvas.getContext) {
const context = canvas.getContext('2d')
context.fillStyle = '#222'
context.fillRect(0, 0, viewportWidth, viewportHeight)
}
html,
body,
canvas {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
box-sizing: border-box;
}
canvas {
vertical-align:top;
}
<canvas id="canvas" resize="true">
Your browser does not support HTML Canvas.
To view this page, use a browser that supports HTML Canvas.
</canvas>
Why should i reset display , is it not a block ?
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas
Content categories Flow content, phrasing content, embedded content, palpable content.
Permitted content Transparent but with no interactive content descendants except for <a>
elements, <button>
elements, <input>
elements whose type attribute is checkbox, radio, or button.
Tag omission None, both the starting and ending tag are mandatory.
Permitted parents Any element that accepts phrasing content.
Permitted ARIA roles Any
DOM interface HTMLCanvasElement
it is treated like any other element that embed content and firefox renders it as an inline-boxe / phrasing content . See what permitted parents are if you did read in diagonal
Other similar elements : https://html.spec.whatwg.org/multipage/dom.html#embedded-content-category