Fixed calculation of margin between elements