views:

513

answers:

1

I have 2 canvas, one use old html "width" and "height" to size it, the other use CSS

<canvas id="compteur1" width="300" height="300" onmousedown="compteurClick(this.id);"></canvas>
<canvas id="compteur2" style="width: 300px; height: 300px;" onmousedown="compteurClick(this.id);"></canvas>

compteur1 display like it should, but not compteur2. the content is drawn using javascript on a 300x300 canvas.

why is there a display difference? Thanks!

Screenshot: alt text

+4  A: 

It seems that the width and height attributes determine the width or height of the canvas's coordinate system, whereas the CSS properties just determine the size of the box in which it will be shown.

(I do think they should make this just a bit clearer in the HTML5 spec...)

SamB
indeed.. I always thought direct attributes like "width" and "height" were deprecated in recent html versions..
Sirber
Oh, apparently it's actually described rather well at http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#attr-canvas-width (section `#attr-canvas-width`). The trouble is that I clicked on the wrong `width` before and went to the `#dom-canvas-width` section instead. Filed http://www.w3.org/Bugs/Public/show_bug.cgi?id=9469 about it.
SamB