Canvas canvas height should be written in the <canvas> tab

Source: Internet
Author: User

Before using canvas to paint, are directly in the canvas label directly written on the width of the high, no problem, but also did not explore why the width of the canvas directly in the label, because the various data examples are so written. Today, Mr Wang raises a question: If you write the width and height in <style>, see what's different. I tried the following, and sure enough there was a problem.

Check the code First:

<! DOCTYPE html>

1. Width: 400, High: 300, direct write in <canvas> effect:

2, delete the <canvas> width, Width: 400; High: 300; effect written in <style>:

Why are the two effects different?

Canvas, like any other label, can also define styles through CSS. However, it is important to note that the default width of canvas is 300px * 150px, the canvas is defined in CSS for a wide height, in fact, the width of 300px * 150px is stretched, if in this case canvas drawing, The graphic you get may be the effect of deformation. Therefore, when you draw a canvas, you should define the width height directly in the canvas label.

Canvas canvas height should be written in the <canvas> tab

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.