It puzzled me and intrigues, I hope.
I am wondering if anyone can point me to the source of this difference in behavior in terms of the CSS / canvas specification, I know other solutions on how to fill the parent container, so don't respond to such answers.
Consider this HTML:
<!DOCTYPE html> <html lang="en"> <head> <style type="text/css"> html, body, #container { height: 100%; width: 100%; padding: 0; margin: 0; } #container { position: relative; } #content { position: absolute; border: 1px solid red; background-color: blue; top: 0; bottom: 0; left: 0; right: 0; width: auto; height: auto; } </style> </head> <body> <div id="container"> <canvas id="content"></canvas> </div> </body> </html>
JSFiddle: http://jsfiddle.net/2zH5H/ . This HTML result causes the default canvas size and width and height to indicate that the canvas specification requires (300x150) instead of filling the parent container according to CSS rules. You can verify that this works without any changes for any other block element, for example div: http://jsfiddle.net/8AQVj/1/
Again, we are talking about the size of the element on the screen, and not about the size of the contents of the canvas. The behavior is consistent in Chrome, Firefox, and IE, so I assume this should be based on a specification somewhere, but I could not find the appropriate snippet.
source share