5
votes

I wrote the following code

 canvas{ width: 1000pt;height: 100pt; margin: 0px;   }
.bluecolor{background-color : skyblue;}
.orangecolor{  background-color : darkblue;}
.indianred{background-color : 	#CD5C5C ;}
 
<html>
<body>
<canvas id="canvas1" class = "orangecolor" > </canvas>
<canvas id="canvas2" class = "bluecolor" > </canvas>
<canvas id="canvas3" class = "indianred" ></canvas>
</body>
</html>

I want to remove the spacing between the canvas elements , and want it to have no space between , them how to achieve it ?

And also why is there any spacing , when I have explicitly made margin to be zero ?

Maybe I am missing a crucial point , I am a beginner in HTML, CSS and JavaScript , and if I have not properly framed my question please mention it in comment below , I will happily do so.

2

2 Answers

6
votes
canvas {
  display: block;
}

this should do the trick.

ok the explaination :

see canvas is inline, so lets consider it like text or for simplicity a character.. now consider character 'w' and 'g' .. now note that 'g' descends lower in line than 'w' , so when character 'g' is rendered there is some space is below the baseline , so when 'wg' is render there is empty space below character 'w' ..

that is the space you see below your inline element canvas.

lets just get out of inline thing and give it a display: block

0
votes

This space is created by line break between </canvas> and <canvas> .

Try to add font-size:0 for parent element of canvas elements,

body{font-size:0}

or remove line break between end tag and begin tag of canvas element like this.

<canvas></canvas><canvas></canvas><canvas></canvas>