Chrome seems to set canvas tags a default width of 300px.
This is a bit of a nuisance when I want a canvas to default to the size of it's containing div, which has an unspecified size.
Using the example here, I'd like the canvas to default to the width of the heading with added padding.
Hope that makes sense.
Is this possible without javascript?
With the Select and Move Tool, click the canvas size label or border to select the canvas. Click the canvas border handles to resize the canvas dynamically. When you drag the border handles without using any keyboard modifiers, the canvas resizes non-uniformly. Hold Shift to constrain the resize proportions.
Description. pixels. Specifies the width of the canvas, in pixels (e.g. "100"). Default value is 300.
2:3 is the most popular aspect ratio for printing. Print sizes that are a 2:3 aspect ratio and are popular with poster, canvas, and decal printing are 24 x 36 inches and 40 x 60 inches. 3:4 Aspect Ratio. Some popular print sizes for the 3:4 ratio includes 30 x 40 inches and 18 x 24 inches.
All web browsers limit the canvas element's width, height, and area. For Google Chrome, the maximum allowable width and height are 32,767 pixels and the maximum allowable area is 268,435,456 pixels.
Finnnn, you are right.
From html5 specification, http://www.w3.org/TR/2012/WD-html5-author-20120329/the-canvas-element.html#the-canvas-element
The canvas element has two attributes to control the size of the coordinate space: width and height.
These attributes, when specified, must have values that are valid non-negative integers.
The width attribute defaults to 300, and the height attribute defaults to 150.
Arrange your layout such that there is a div and that div's only job is to dictate and be the size you want the canvas to be.
var canvas = document.createElement('canvas');
canvas.width = div.clientWidth;
canvas.height = div.clientHeight;
Then add the canvas to the div.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With