This article mainly introduces why canvas needs to directly define width and height in the tag. It has been specially tested, which is very practical and recommended to friends.
In the past, when I used canvas to draw pictures, I would write width and height directly in the canvas tag. There is no problem, but I have never explored why width and height should be written directly in the canvas tag, because this is what I wrote on examples of each material. Today, Wang Sir asked a question: If you write the width and height in <style>, see what the difference will be. I tried the following by myself, and there was indeed a problem.
Let's take a look at the code first:
Copy the code