If the parent element with relative is not set, and you set the absolute position, this will affect your element to get the position from x (0) and y (0) (edge ββof the upper left screen), if you set for example 2 divs, the first one with position:relative , and its child has a position: absolute; that the child will depend on x (0), y (0) on its parent position.
<div style="position:absolute;">One</div> <-- this one will be on the left top of the screen , <div style="position:relative;"> <div style="position:absolute;">Here you go boy</div> </div> (this children element gets the position of its parent element , not of the top-left screen)
In your case, you set both elements (div and span) position:absolute , if there is no parent element with position:relative; , they automatically go to the upper left corner and remain left (0) at the top (0). If you want your span to inherit the position of the div, you first set position:relative; in the div and position:absolute to your range, and after that you have to adjust the left and top pixels, depending on where your element wants to be located, there is a simple code below
===================================================
FIRST CASE: NO POSITIONING INHERITANCE! HTML
<div> <span>Test child</span> </div>
CSS
div{ height:100px; width:100px; border:2px solid black; margin:0 auto; } span{ position:absolute; left:0px; top:0px; }
In this code, I placed your div in the middle, (margin:0 auto) . I set position:absolute to your range and left:0 , top:0 (there is no inheritance, because the div does not contain position:relative; ).
===============================
SECOND CASE - INHERITANCE
CSS:
div{ height:100px; width:100px; border:2px solid black; margin:0 auto; position:relative; } span{ position:absolute; left:0px; top:0px; }
Now your range depends on the position of the div and will be placed at x (0) and y (0) in your div, and not on the screen. I hope you understand this.