放在<p>之后<div>


之后。

我用 DOM 结构制作了一个网站,如下所示:

<body>
<div><canvas id="cv"></canvas>
<script>
..some scripts with function and methods to make multiple canvas..
</script>
</div>
<p>lorem ipsum</p>
</body>

问题是"Lorem ipsum"段落总是出现在画布后面我不能让它出现在画布之后或至少出现在 之后,这应该是这样的,

在脚本上,我使用"createElement"和"appendChild"方法来制作多个画布,并将新画布附加到div标签中

有什么想法让该段落出现在下面吗?(在画布之后不落后)

完整的页面或多或少具有相同的结构,如下所示:

<html>
<body>
<div id="layer">
<canvas id="myCanvas" width="400" height="300" style="border:2px solid #c3c3c3;position:absolute;left:5px;top:5px">Your browser does not support the canvas element.</canvas>
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="#FF0000";
ctx.fillRect(0,0,150,75);
var id=document.createAttribute("id");
id.nodeValue="test";
var cs=document.createElement("canvas");
document.getElementById("layer").appendChild(cs).setAttributeNode(id);
document.getElementById("test").style.position="absolute";
document.getElementById("test").style.left="7px";
document.getElementById("test").style.top="7px";
document.getElementById("test").width="100";
document.getElementById("test").height="180";
document.getElementById("test").style.border="1px solid";
</script>
</div>
<p>dssdsdsds dsds vdok fekof efienife fienfie fkenfke fkeinf ekfine</p>
</body>
</html>

如果您希望其他元素在元素周围流动,请不要绝对定位元素。如果你真的需要绝对定位,那么定位容纳你想要保持在一起的所有东西的容器。

最新更新