Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS canvas width in % not works get converted to px Reply To: canvas width in % not works get converted to px

#189371
MattDiMu
Participant

AFAIK the height and width defined as attributes of a canvas element, just define the the original size of the canvas, just like every image already has its own width and height (which is used, when width:auto; and height: auto; are set by CSS).

So it should be possible to generate a canvas with a certain size (defined by width and height attributes) and resize it afterwards by using css width and css height:

<canvas id=”canvas” width=”1000″ height=”500″></canvas>

#canvas {
width: 100%;
}

The quality might suffer through this, as the canvas is resized by css, but basically it should work.