When can offset properties be used?


#1



In exercise 3 it states "Note that offset properties will not work if the position of the element is not set to relative." However, in exercise 4 it says to use offset properties for the absolute value as well. Is exercise 3 incorrect in saying that offset properties can only be used if the position is set to the relative value?


Replace this line with your code.


#2

When no position is specified, the default is static, which has no offset. An absolutely positioned element will take the top left corner of the body element as a reference, unless it is contained in another element with position: relative. It will then take that container's top left corner as a reference. We can then set the offset from that position.

<div style="width: 200px;
            height: 200px; 
            border: 1px solid black; 
            position: relative;
            top: 50px;
            left: 50px">
  <div style="width: 100px; 
              height: 100px; 
              border: 1px solid black; 
              position: absolute;
              top: 50px;
              left: 50px">
  </div>
</div>

In the above example, the outer div will be 50px from the top, and 50px from the left edge of the window. The inner div will be inside the outer div, again 50px from top and left.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.