Horizontal Alignment of Floated Divs
In cases where divs are floated left within a container with overflow: hidden, they may stack vertically even when there is sufficient space horizontally. To ensure they align correctly, consider the following solution:
Solution:
Create an inner div within the container that has a wider width, sufficient to accommodate all the floated divs.
#container { width: 200px; overflow: hidden; } #inner { width: 2000px; overflow: hidden; } .child { float: left; width: 50px; height: 50px; }
<div>
By providing ample width in the inner div, the floated divs will align horizontally within the container, as intended.
The above is the detailed content of Why Do Floated Divs Stack Vertically Even with Overflow:hidden?. For more information, please follow other related articles on the PHP Chinese website!