0

How to put the border inside the canvas, so it is not expanded by the border:

<canvas width="50" height="50" style="border: 10px solid black"></canvas>



is much bigger than 

<canvas width="50" height="50" style="border: 1px solid black"></canvas>

box-sizing: border-box; doesn't help in this case

Please not that the canvas I am using is rectangular and its shape is not controlled via JavaScript.

Hairi
  • 3,318
  • 2
  • 29
  • 68

1 Answers1

0

Use box-shadow in this case if you want to set the width & height by attribute.

#canvas1 {
  -webkit-box-shadow:inset 0px 0px 0px 10px #000;
   -moz-box-shadow:inset 0px 0px 0px 10px #000;
   box-shadow:inset 0px 0px 0px 10px #000;
}

#canvas2 {
  -webkit-box-shadow:inset 0px 0px 0px 1px #000;
   -moz-box-shadow:inset 0px 0px 0px 1px #000;
   box-shadow:inset 0px 0px 0px 1px #000;
}
<canvas id="canvas1" width="50" height="50"></canvas>
<canvas id="canvas2" width="50" height="50"></canvas>
Jared Chu
  • 2,757
  • 4
  • 27
  • 38