Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place two canvases on top of one another?

Tags:

html

canvas

I found similar topics but they all used absolute positioning which placed the canvases at the top left of the page. I have them contained within a div but I'm not sure exactly how to get them to layer properly. I tried using absolute and relative positioning in CSS but I wasn't having any luck.

like image 980
Ryan Peschel Avatar asked Oct 22 '25 14:10

Ryan Peschel


2 Answers

Do this:

<style>
    #container { position: relative; }
    .canvas { position: absolute; top: 0; left: 0; }
</style>

<div id="container">
    <canvas class="canvas" id="canvas1"></canvas>
    <canvas class="canvas" id="canvas2"></canvas>
</div>
like image 106
Searle Avatar answered Oct 24 '25 07:10

Searle


Make sure to add position: relative to the containing div in order to position the canvas elements absolutely within it.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!