0

I have read a few stackoverflow post about position:absolute without top/right/left/bottom. Post 1 Post 2 Post 3

They all give similar answers. which is that an element with position:absolute without top/right/left/bottom would

  • 1.The element will be out of normal flow of the web document (the is very clear)

  • 2.It remains in the static position, which basically means its usual spot in the layout had it not been positioned at all.

I can find an example in which point 2 seems doesn't hold. Consider the following example: Absolute position example Static position example

The only difference between these 2 example is that one has position: static for h2 tag while another one has position: absolute for h2 tag. By comparing two examples, the h2 tag with position: absolute is positioned slightly lower thn that of position: static. I am confused because if point 2 is true, the h2 tag in both examples should be positioned in the same positioncomparing . Could anyone kindly explain to me why the h2 tags are not in the same position? And how does the position:absolute function without top/bot/left/right ?

user13641224
  • 161
  • 1
  • 9
  • 1
    default body margin and margin-collapsing is happening in the static position but not in the absolute one (remove body margin and both will be the same) – Temani Afif Jun 24 '20 at 16:10
  • Hello. I am learning coding and therefore I don't understand what do you mean body margin and margin collapsing (I have read the solution post too). Would you mind giving me some detailed explanation please? – user13641224 Jun 25 '20 at 00:50
  • body has a default margin (8px) and h2 has also a default margin, you can find this while inspecting both element. Both margin are collapsing in the first case when using static (as explained in the duplicate) but not in the case where using position:absolute because there is no margin collapsing with position:absolute. If you follow the duplicate you will find all the cases when margin collapsing is happening – Temani Afif Jun 25 '20 at 07:58

0 Answers0