I have the following code:
<!DOCTYPE html> <html> <head> <style> img { position:absolute; right:50px; } </style> </head> <body> <h1>This is a heading</h1> <img src="logocss.gif" width="95" height="84" /> </body> </html>
from http://www.w3schools.com/cssref/tryit.asp?filename=trycss_position_right
If I change the style of h1 to: h1 {position: absolute; right: 50px; } then both h1 and img overlap.
Now I have not mentioned the top position for img or h1. Thus, in the first case, when h1 had no style, img left h1 alone and took the next available space after h1 and was aligned on the right side (50 px separately). But when I mentioned that h1 will be split into 50 pixels (with absolute positioning), both img and h1 overlap. Now that I have not mentioned the top position, why not leave img, leaving h1 alone and follow it (instead of overlapping it)? I understand that we use absolute positioning, which leaves the top position ambiguous, so why does it automatically assume that img should occupy the top position: 0? If h1 is in the top position: 0, then this is normal, because it is the first element. But img must respect the space h1.
Thanks in advance for your help.
source share