Skip to content
Advertisement

how to create box in HTML5?

I am trying to create two inner box . I am able to do in using HTML css . working link (expected output) https://stackblitz.com/edit/js-lvzg4o?file=index.js enter image description here

When I trying to do the same thing using Canvas. I am not able create two box or container where I will put my text.

is it possible to do same thing using canvas

JavaScript

here is my code https://stackblitz.com/edit/js-6ameba?file=index.js

current output

Advertisement

Answer

Begin your drawing movements with ctx.beginPath()

In order for canvas to know when to start tracking movement, you need to invoke beginPath() on the 2d context. There is no need for two contexts.

Important note, Canvas is NOT html, You will need to do the math to calculate line wrapping yourself. There is a measureText(string) method that will provide you with the information based on font family and size.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement