Relative CSS positioning

T

Tim Johansson

Hello,

I have an image, upon which I want to place another image. I've figured out
this should be done by CSS positioning, but I don't know the exact
coordinates of the other image. How do I place the image knowing only where
on the other image I want to place it?
 
S

Spartanicus

Tim Johansson said:
I have an image, upon which I want to place another image. I've figured out
this should be done by CSS positioning

Try negative margins first.
 
T

Tim Johansson

rf said:
Tim Johansson


Why not use your image composing software?
The image's position is calculated by PHP, and creating images on-the-fly
would consume too much time and bandwidth.
 
R

rf

Tim Johansson
The image's position is calculated by PHP, and creating images on-the-fly
would consume too much time and bandwidth.

Hmmm. Off top of head solution #1...

Create a div exactly the same size as the first image. Background of div is
first image. Position: relative so it becomes a containing element (no top
or left).

Inside the div an <img> pointing to the second image. Position: absolute.
Top: and bottom: now refer to the top left of the div, that is the first
image. If the first image (the div really) moves then so does the second
image.

You don't need to know where the first image is positioned (which is a real
hard thing to determine anyway (client side) and usually impossible server
side).

<tinkers/>
http://users.bigpond.net.au/rf/images.html

Be sure to change your font size so you can see that when to roo moves so
does the bug.
 
S

Sid Ismail

: I have an image, upon which I want to place another image. I've figured out
: this should be done by CSS positioning, but I don't know the exact
: coordinates of the other image. How do I place the image knowing only where
: on the other image I want to place it?

Use a graphics editor, surely? PSP or Irfanview.

Sid
 
T

Tim Johansson

rf said:
Tim Johansson

Hmmm. Off top of head solution #1...

Create a div exactly the same size as the first image. Background of div is
first image. Position: relative so it becomes a containing element (no top
or left).

Inside the div an <img> pointing to the second image. Position: absolute.
Top: and bottom: now refer to the top left of the div, that is the first
image. If the first image (the div really) moves then so does the second
image.

You don't need to know where the first image is positioned (which is a real
hard thing to determine anyway (client side) and usually impossible server
side).

<tinkers/>
http://users.bigpond.net.au/rf/images.html

Be sure to change your font size so you can see that when to roo moves so
does the bug.

It worked great, thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top