Я добавил свойство позиции к #canvas1
и использовал свойство z-index
.Чем выше значение z-index
, тем выше оно будет отображаться.Все, что вам нужно, это чтобы z-index
во всем, что вы хотите сверху, было выше, чем z-index
того, что вы хотите ниже.
#canvas1 {
position: relative;
background: black;
z-index: -1;
}
#canvas2{
position: absolute;
top: 0;
left: 0;
background-color: red;
z-index: 0;
}
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<div class="container">
<canvas class="canvas" id="canvas1" width="500" height="500"></canvas>
<canvas class="canvas" id="canvas2" width="500" height="500"></canvas>
</div>
</body>
</html>