The following code creates an 800x600 pixels div
containing an 300x150 pixels (default size) canvas
:
div [ style "width" "800px"
, style "height" "600px"
, Html.Attributes.id ("item-" ++ String.fromInt 1) ]
[
canvas [ ] [ ]
]
]
There are two ways to resize the canvas:
- By using
width
andheight
properties. - By using
style "width" "..."
andstyle "height" "..."
.
If I choose the 1rst method and change the canvas size to, for example, 400x500, the contained image (or drawing) isn’t stretched.
canvas [
width 500
, height 400
] [ ]
(I cannot post this picture, because new users can only post 1 embedded media per post…)
When I use the 2nd method the canvas is stretched. The following image is an example of an 500x300 pixels image, drawn into a 500x400 canvas
, which in turn is inside an 800x600 div
. As you can see the image is stretched.
canvas [
style "width" "500px"
, style "height" "400px"
] [ ]
Knowing this, I would like to know the size of the parent div
and assign the same width
and height
to the canvas
, how can I do that?.