Sometimes, we want to fix canvas is stretched when using CSS but normal with width and height properties with JavaScript.
In this article, we’ll look at how to fix canvas is stretched when using CSS but normal with width and height properties with JavaScript.
How to fix canvas is stretched when using CSS but normal with width and height properties with JavaScript?
To fix canvas is stretched when using CSS but normal with width and height properties with JavaScript, we set the width and height with JavaScript.
For instance, we write
const canvas = document.getElementById("canv");
canvas.setAttribute("width", "438");
canvas.setAttribute("height", "462");
to get the canvas with getElementById
.
Then we call setAttribute
to set the width and height attribute values.
Conclusion
To fix canvas is stretched when using CSS but normal with width and height properties with JavaScript, we set the width and height with JavaScript.