When we create an HTML5 canvas element, a ghost margin appears below the canvas element even though we set the margin and padding to 0.
Example: http://jsfiddle.net/yvbmd/
We tried a variety of things, but can’t erase the ghost margin.
How can we create the canvas element without that ghost margin?
Add
vertical-align: bottomto it.This is caused by the canvas being an inline element. As such, it is effectively considered a character. As such, it must follow the baseline rule, which is to leave a little space below the line in case of characters such as
gjpqywhich drop below the baseline. By setting thevertical-aligntobottom, you are actually aligning the canvas to the bottom of the drop-down letters. So long as the canvas itself is taller than theline-height, you will have no problems. Should the canvas be shorter than theline-height, you will start seeing “ghost margins” above the canvas as it reserves room forbdfhklt, the taller letters. This can be fixed by adding aline-height: 1pxrule.