Note the blank line at the bottom of the canvas. It’s impossible to draw on that line.
How can the entire canvas be used for drawing (in full resolution)?
Browser: 54.0.2840.99 (Official Build) m (32-bit) / Windows 7
Run in full page:
var el = document.getElementsByTagName("canvas")[0];
var ctx = el.getContext("2d");
el.width = el.clientWidth;
el.height = el.clientHeight;
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(el.width, el.height);
ctx.lineTo(0, el.height);
ctx.fill();
ctx.closePath();
html {
height: 100%;
}
body {
display: flex;
flex-direction: column;
height: 100%;
width: 667.19px; /* = `80vh` in viewport of 834 px height */
}
.bar {
flex: auto;
background: black;
height: 20px;
}
#display {
position: relative;
width: 100%;
height: 0;
padding-bottom: 100%;
}
canvas {
position: absolute;
width: 100%;
height: 100%;
}
<div class="bar"></div>
<div id="display">
<canvas></canvas>
</div>
<div class="bar"></div>
To make it clear: The JavaScript code above adjusts the pixel dimensions of the canvas to match them with those of the canvas element. This question is about an area of the canvas which cannot be drawn upon.