search

Home  >  Q&A  >  body text

javascript - Why is the body height 4 pixels more than the canvas height?

css:

html,body {
  margin: 0;
  padding: 0;
}
canvas {
  margin: 0;
  padding: 0;
}

html:

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

javascript:

dt = document.getElementById('canvas');
dt.width = window.innerWidth;
dt.height = window.innerHeight;

The result is like this:

Logically shouldn’t canvas be as high as body? Why does body have 4 extra pixels?
Please tell me, thank you!

扔个三星炸死你扔个三星炸死你2706 days ago683

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-07-05 10:50:24

    Add

    to body
    body {
        font-size: 0
    }

    Please see: http://www.w3cplus.com/css/fi...

    reply
    0
  • Cancelreply