css - Is it possible to relatively position an element OVER a relatively positioned canvas? -
here problem:
i have canvas
element center in documentelement
using javascript. has relative position can still flow nicely p elements above , below it. put p element on top of canvas. right i'm doing this:
var element=document.getelementbyid("my_canvas_element"); while(element.parentelement){ offset_x+=element.offsetleft; offset_y+=element.offsettop; element=element.parentelement; } my_p_element.style.left=offset_x+"px"; my_p_element.style.top=offset_y+"px";
this accurately position my_p_element
@ top left corner of canvas element long set my_p_element
's css position absolute. there way position my_p_element
in top left corner of relatively positioned canvas element using css?
that is, there way place p element in top left corner of relatively positioned canvas using css?
thanks!
how wrapping canvas , paragraph elements in div div position:relative.
then can position:absolute canvas , paragraphs needed relative parent div.
body{ background-color: ivory; padding:0px;} #wrapper{position:relative; border:1px solid blue; width:300px; height:300px; } #p1{position:absolute; top:-15px; border:1px solid green;} #canvas{position:absolute; border:1px solid red;}
<div id=wrapper> <p id=p1>i'm top-left paragraph element</p> <canvas id="canvas" width=300 height=300></canvas> </div>
Comments
Post a Comment