Fix bug with non-linear layouts

When a grid system such as Bootstrap is used, the order of elements
vertically is not always the same as the order in the HTML source, due
to the use of floating columns. This caused layout errors, which are
fixed by this patch.