If you want the element to remain in its static position (where it would normally be if it weren’t placed), but simply take it out of the normal flow, just indicating position: absolute is perfectly acceptable. The behavior is the same as described in sections 10.3.7 and 10.6.4 of the specification, and each browser behaves correctly.
You are not required to give it any offsets if you do not want to move the element from its usual static position, and you do not need to relatively position its parent element if you are not going to move the element anywhere, since it will still remain in the static position.
I looked at your code again and noticed that you are applying a percentage addition to your item that is excluded from the list. You will need to relatively position the parent element if you want the percentage addition to be calculated based on the width of this parent element, and not the original containing block (where the root element is located):
#parent{ position:relative; width:50%; margin:10% auto; background:gold; height:20%; }
Compare this script with the original .
So, the main goal regarding the positioning of some ancestor of an absolutely positioned element is to designate its containing block. Sections 9 and 10 have most of the details about the interaction between elements and their containing blocks. Depending on your layout, you may not need to position anything else at all, however, if your layout is quite complex, you may find that there are side effects that arise from whether you are positioning any elements of the container and what position you occupy. I suspect that the topic of containing blocks can be considered in another question, since it can be very far from the scope of this.
source share