What is the difference between setting the size ( width , height ) of an object in the form width="50px" and style="width:50px;" ?
It is expressed in the fact that canvas created with dimensions in the form width="50px" heght="50px" is filled with the command
<context_canvas'a>.fillRect ( 0 , 0 , 50 , 50 ) ; correctly, but in the form style="width:50px;height:50px;" only partially.
Or, after all, these parameter declarations are not interchangeable?
Here is the code:
<!DOCTYPE HTML> <html> <head> <title>Документ Без Имени</title> <meta charset="utf-8"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> $(document).ready(function() { var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.fillRect ( 0 , 0 , 200 , 30 ) ; }); </script> </head> <body> <!-- <canvas id="myCanvas" style="height: 30px; width: 200px; "> </canvas> --> <canvas id="myCanvas" height="30" width="200"> </canvas> </body> </html> The first canvas is crooked, and the second is normal ...
50pxis the wrong value for the width attribute. Correct -50. - andreymal