在HTML中将两个画布放在同一行,可以使用CSS的布局属性来实现。以下是一种常见的方法:
<div id="canvas-container"></div>
#canvas-container {
display: flex;
flex-direction: row;
}
var canvas1 = document.createElement("canvas");
var canvas2 = document.createElement("canvas");
document.getElementById("canvas-container").appendChild(canvas1);
document.getElementById("canvas-container").appendChild(canvas2);
完整的HTML代码如下:
<!DOCTYPE html>
<html>
<head>
<style>
#canvas-container {
display: flex;
flex-direction: row;
}
</style>
</head>
<body>
<div id="canvas-container"></div>
<script>
var canvas1 = document.createElement("canvas");
var canvas2 = document.createElement("canvas");
document.getElementById("canvas-container").appendChild(canvas1);
document.getElementById("canvas-container").appendChild(canvas2);
</script>
</body>
</html>
这样,两个画布就会水平排列在同一行上。你可以根据需要调整画布的大小和样式。
领取专属 10元无门槛券
手把手带您无忧上云