Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Positioning objects in DHTML

Status
Not open for further replies.

oRBIT

Programmer
May 15, 2000
3
SE
How do I position an image (for example) relative to another image? For example, if I want to position &quot;image2&quot; at the same position that &quot;Image1&quot; have (+- X/Y pixels). I don't want to use &quot;absolute&quot; coordinates to force my images to a certain location so the solution has to be a little bit more friendly.<br>Ideas are appreciated.<br>
 
&lt;img id=jack src=about1.gif width=135 height=20 border=0&gt;<br>&lt;img id=jill style=position:relative;left:10;top:50; src=aboutheader.gif width=139 height=31&nbsp;&nbsp;border=0&gt;<br><br>this will position jill 10 pixels to the right and 50<br>pixels down from jack<br><br>
 
Is it possible to do this in layers somehow to avoid getting the surrounding HTML-code to look weird? Nothing happens when I use the &quot;z-index&quot;... :/
 
hmm, dynamic positioning is an absolute pixel-pixel relations, basically since the browser isnt going to autoformat if something changes on the client side, you might have to control all the other parts as well, have you tried moving it in a &lt;DIV&gt; <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)
 
With DIV things actually start to happen. :) <br>However, how do I write in Javascript to set equal positions of, for example, two DIV-blocks?
 
all you need is something like this:<br><br>function setPosEq(divId1,divId2,diff){<br>//div one is the pre-positioned one, and div two is moved to<br>//diff pixels from div one.<br><br>div1=(document.layers)?eval('document.layers.'+divId1):(document.all)?eval('document.all.'+divId1+'.style):null;<br><br>div2=(document.layers)?eval('document.layers.'+divId2):(document.all)?eval('document.all.'+divId2+'.style):null;<br><br>if (div1 && div2){<br>div2.top=parseInt(div1.top)+diff; div2.left=parseInt(div1.left)+diff;}<br>}<br>}<br><br>I hope this helps (and works). <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top