Reimplementation of CSS layout using pure JavaScript