admin管理员组

文章数量:1418717

I am trying to place two canvas nearby. But unfortunately when i include two canvas it automatically produces a space between two canvas. How to remove that empty space or how to join that two canvas. Here is my fiddle Fiddle

here is my code:

<canvas id="button" width="30" height="30" style="border:1px solid #d3d3d3;background-color:green;"></canvas> 
<canvas id="button" width="30" height="30" style="border:1px solid #d3d3d3;background-color:green;"></canvas> 
​

here is the script:

window.onload=function()
{
var canvas = document.getElementById("button");
var ctx = canvas.getContext('2d');
}​

I am trying to place two canvas nearby. But unfortunately when i include two canvas it automatically produces a space between two canvas. How to remove that empty space or how to join that two canvas. Here is my fiddle Fiddle

here is my code:

<canvas id="button" width="30" height="30" style="border:1px solid #d3d3d3;background-color:green;"></canvas> 
<canvas id="button" width="30" height="30" style="border:1px solid #d3d3d3;background-color:green;"></canvas> 
​

here is the script:

window.onload=function()
{
var canvas = document.getElementById("button");
var ctx = canvas.getContext('2d');
}​
Share Improve this question asked Dec 19, 2012 at 3:55 Praveen SinghPraveen Singh 5422 gold badges10 silver badges23 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

The newline in the HTML is being treated as a space. Simply get rid of the whitespace between the two canvases:

<canvas id="button" width="30" height="30" style="border:1px solid #d3d3d3;background-color:green;">
</canvas><canvas id="button" width="30" height="30" style="border:1px solid #d3d3d3;background-color:green;">
</canvas>

See fiddle.

Or use:

<canvas id="button" width="30" height="30" style="border:1px solid #d3d3d3;background-color:green;"></canvas><!--
--><canvas id="button" width="30" height="30" style="border:1px solid #d3d3d3;background-color:green;"></canvas>

本文标签: javascriptReduce the space between two canvas htmlStack Overflow