I
I
Ibishka2020-02-02 16:34:17
Canvas
Ibishka, 2020-02-02 16:34:17

How to center canvas in the middle?

How to center canvas in the middle?

const canvas = document.querySelector("#canvas"),
  ctx = canvas.getContext("2d");

canvas.width = (window.innerWidth * 90) / 100;
canvas.height = (window.innerHeight * 90) / 100;

ctx.fillRect(0, 0, canvas.width, canvas.height);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MagicMight, 2020-02-02
@MagicMight

Here is the solution.
https://codepen.io/MagicMight/pen/abzewde

I
Ilya Muromtsev, 2020-02-02
@sfrancisco

canvas {
   display: block;
   margin: 0 auto;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question