如何让这些画布正确对齐?
How do I get these canvases to align properly?
我试图将三个画布叠加显示,但它们只是并排显示。我对 css 的经验很少。我需要添加什么?
<body>
<div id="canvas_container">
<canvas id="Background" width="330" height="330"></canvas>
<canvas id="mycanvas" width="330" height="330"></canvas>
<canvas id="Overlay" width="330" height="330"></canvas>
</div>
<style>
.canvas_container {
position: relative;
}
.container > canvas {
position: absolute;
top: 0;
left: 0;
}
</style>
<div id="codeinput">
<br>
The "X" goes here:<input type="text" id="shapeX">
<br>
The "Y" goes here:<input type="text" id="shapeY">
<br>
Choose the color: <input type="text" id="shapeColor" value="green">
<script>
unrelated javascript
</script>
<br>
<button onclick=makeSquare();>Draw shape</button>
</div>
</body>
你的 css 不错,但你设置了错误的选择器。您有 id = canvas_container
,但为 class canvas_container
和 class container
设置了样式
#canvas_container {
position: relative;
width: 330px;
height: 330px;
}
#canvas_container > canvas {
position: absolute;
top: 0;
left: 0;
border: 1px solid red;
}
<div id="canvas_container">
<canvas id="Background" width="330" height="330"></canvas>
<canvas id="mycanvas" width="330" height="330"></canvas>
<canvas id="Overlay" width="330" height="330"></canvas>
</div>
<div id="codeinput">
<br>
The "X" goes here:<input type="text" id="shapeX">
<br>
The "Y" goes here:<input type="text" id="shapeY">
<br>
Choose the color: <input type="text" id="shapeColor" value="green">
<br>
<button onclick=makeSquare();>Draw shape</button>
</div>
我试图将三个画布叠加显示,但它们只是并排显示。我对 css 的经验很少。我需要添加什么?
<body>
<div id="canvas_container">
<canvas id="Background" width="330" height="330"></canvas>
<canvas id="mycanvas" width="330" height="330"></canvas>
<canvas id="Overlay" width="330" height="330"></canvas>
</div>
<style>
.canvas_container {
position: relative;
}
.container > canvas {
position: absolute;
top: 0;
left: 0;
}
</style>
<div id="codeinput">
<br>
The "X" goes here:<input type="text" id="shapeX">
<br>
The "Y" goes here:<input type="text" id="shapeY">
<br>
Choose the color: <input type="text" id="shapeColor" value="green">
<script>
unrelated javascript
</script>
<br>
<button onclick=makeSquare();>Draw shape</button>
</div>
</body>
你的 css 不错,但你设置了错误的选择器。您有 id = canvas_container
,但为 class canvas_container
和 class container
#canvas_container {
position: relative;
width: 330px;
height: 330px;
}
#canvas_container > canvas {
position: absolute;
top: 0;
left: 0;
border: 1px solid red;
}
<div id="canvas_container">
<canvas id="Background" width="330" height="330"></canvas>
<canvas id="mycanvas" width="330" height="330"></canvas>
<canvas id="Overlay" width="330" height="330"></canvas>
</div>
<div id="codeinput">
<br>
The "X" goes here:<input type="text" id="shapeX">
<br>
The "Y" goes here:<input type="text" id="shapeY">
<br>
Choose the color: <input type="text" id="shapeColor" value="green">
<br>
<button onclick=makeSquare();>Draw shape</button>
</div>