Heim  >  Fragen und Antworten  >  Hauptteil

javascript - Warum ist die Körperhöhe 4 Pixel größer als die Leinwandhöhe?

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;

Das Ergebnis sieht so aus:

Sollte die Leinwand nicht logischerweise die gleiche Höhe wie der Körper haben? Warum hat der Körper 4 zusätzliche Pixel?
Bitte sag es mir, danke!

扔个三星炸死你扔个三星炸死你2662 Tage vor649

Antworte allen(1)Ich werde antworten

  • 我想大声告诉你

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

    给body添加

    body {
        font-size: 0
    }

    具体请看:http://www.w3cplus.com/css/fi...

    Antwort
    0
  • StornierenAntwort