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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

positioning an image 2

Status
Not open for further replies.

bikh

Programmer
May 3, 2002
25
US
I have a table that is center aligned. I want to position an image on top of it (higher z-index) but at a certain position relative to the table. How can I do this?
 
Wrap the image inside of a DIV, and position the DIV element accordingly.

I.E. ...

.wrapperDIV {
position: relative ;
top: -20px ; /* relative to your table */
left: 100px ; /* relative to your table */
z-index: 1000 ; /* ensure it's on top of all */
}

then your HTML looks like:

<!-- more code here ... -->

<table>
<tr><td>blah blah blah</td></tr>
<!-- more table stuff here -->
</table>
<div class=&quot;wrapperDIV&quot;>
<img src=&quot;myImage.gif&quot; height=&quot;100&quot; width=&quot;100&quot; alt=&quot;myImage&quot;>
</div>

<!-- more code here ... -->

HTH

Greg Tammi, IT Design & Consultation
Work: Home:
 
thanks for the input grtammi.
I tried out your code and it positioned the image relative to the page and not the table. So when you expand the browser window, the table moves, but the image remained fixed. And I need the image to be positioned relative to the table.
 

You'd want to do something like this:

Code:
<div style=&quot;position:relative;&quot;>
	<table>
		<tr><td>blah blah blah</td></tr>
	</table>
	<div style=&quot;position:relative;left:20px;top:20px;&quot;>
	  	<img src=&quot;myImage.gif&quot;>
	</div>
</div>

Hope this helps!

Dan
 
As BillyRay shows in his example, when DIVs are relative, they are relative to their enclosing container.

If the DIV is sitting alone on the HTML page, then the enclosing container is the page itself. If the DIV sits within another DIV (called &quot;outer&quot;, say), then the DIV (called &quot;outer&quot;) is the enclosing container.

This very simple rule will help you set up your DIVs without experiencing unexpected behaviour when you resize the page.

Jeff
 
Dan, Jeff, thank you for the tips and the explanation, it worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top