![](/img/trans.png)
[英]Placing a canvas within a div such that the canvas changes its size according to the div and reducing the gap between the cursor and pen in canvas
[英]Canvas with block display still has gap between div and canvas element
打開並檢查元素,您會看到畫布和頂部之間存在間隙。
我如何消除這一差距?
<html>
<title>Canvas demo</title>
<body bgcolor="black" style="overflow: hidden">
<center>
<div id="game_container">
<canvas id="canvas" style= "width: 780px; height: 780px; cursor: none;">
</canvas>
</div>
</center>
</body>
<script>
var canvas = document.getElementById('canvas');
canvas.style.display = 'block';
</script>
我猜它給默認保證金的那個身體試試
html,body,canvas{margin:0;padding:0;border:0;font-size: 100%;width:100%;height:100%;}
這應該解決
您可以在這種情況下使用重置CSS。
canvas {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.