The Float two Divs Next to one div Problem

Two left-floated divs placed next to a right-floating div will cause the right-div to get pushed down.

Edited: 2017-03-12 14:53

By. Jacob

In a float based two column layout, I recently had two divs next to one div, totaling 3 divs. One floated right, the other two was floated left. This unexpectedly caused the right floated div to be pushed below the first left floated div.

The problem is likely caused by how CSS defines floated elements, but can be easily solved by using an additional wrapper.

Usually, when this happens for two floated divs, it will be caused by incorrectly clearing floats. Typically a div with clear:both; can also cause it.

Below screenshot shows the problem in my case:

The solution is to use a wrapper

The solution is to create one or more wrapperdivs. For example, you could create one to contain all left column elements, and another to contain all the right column elements.

Alternatively, you could simply use absolute positioning for the right column, but it is probably easier to simply have a wrapper.

In this case, I choose to fix the problem using a single wrapper for the left floated elements: