Home >Web Front-end >CSS Tutorial >Why Do Floated Divs Stack Vertically Even with Overflow:hidden?

Why Do Floated Divs Stack Vertically Even with Overflow:hidden?

DDD
DDDOriginal
2024-11-13 14:43:02455browse

Why Do Floated Divs Stack Vertically Even with Overflow:hidden?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn