0

See below, the "frame" is a 480(w) by 240(h). And yet, When Y is set yo 120, it draws a 160px, as can be seen in the snippet.

let canvas = document.getElementById("canvas");
let ctx = canvas.getContext("2d");

ctx.lineWidth = 4;
ctx.strokeStyle = "#000";

ctx.beginPath();
ctx.moveTo(120, 0);
ctx.lineTo(120, 120);
ctx.stroke();
* {
  margin: 0;
  padding: 0;
}

canvas {
  border: 1px solid #d0d0d0;
  justify-content: center;
  vertical-align: middle;
  width: 480px;
  height: 240px;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -120px;
  margin-left: -240px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
</head>

<body>
  <canvas id="canvas"></canvas>
</body>

</html>
Tzury Bar Yochay
  • 8,798
  • 5
  • 49
  • 73

0 Answers0