// to thi...">

Fabric.js ... how to center the canvas

fabricjs converts:

//  this DOM structure
<div id="wrapper">
  <canvas id="c"></canvas>
</div>

//  to this:
<div id="wrapper">
  <div class="canvas-container">
    <canvas class="upper-canvas"></canvas>
    <canvas class="lower-canvas" id="c"></canvas>
  </div>
</div>

... see this explanation

Due to the way the js fabric wraps the canvas element, how you hold the canvas horizontally in the center.

here is a question like . here is the script test

+5
source share
1 answer

apply

margin: 0 auto;

to class = canvas-container

canvas-container is automatically created by the fabric.

see fiddle

+6
source

All Articles