here is a simple example:
https://jsbin.com/jubiwadase/edit?html,css,output
as you can see, the blocks are now below each other, go ahead and uncomment the display inline-block, as you can see, the blocks now behave different. They are now in one line (horizontal instead of the vertical default)
as for position relative, first please study this example:
https://jsbin.com/bulabinane/edit?html,css,output
as you can see, when #first
is rendered, the element is pushed down before #second
is rendered, so #second
is also pushed down.
now lets change the example slightly:
https://jsbin.com/soruwizewe/edit?html,css,output
as you can see, the elements are rendered first, and then #first
is moved down (by top
), and #second
stays where it. So that is relative position. They are rendered relative to there original position.
if you remember from the first example, elements are rendered one after each other, however absolute positioned elements are taken out of this “flow”, as the following example demonstrates:
https://jsbin.com/tabipeyela/edit?html,css,output
absolute position elements do follow some rules, take a look at this example:
https://jsbin.com/vafoyaruqi/edit?html,css,output
the absolute position element relative to the first non-static parent. Even though the #inner
element (which has position: absolute;) is nested within #outer
, it doesn’t respect #outer
s boundaries.
however, #wrapper
is relatively positioned, so #inner
stays within #wrapper
figuring out how all the elements work together is tricky. Have you learned to use the inspector yet? It can be quite useful