Home > Web Front-end > CSS Tutorial > How to Create a Fluid Layout with Equally Spaced DIVs Using CSS?

How to Create a Fluid Layout with Equally Spaced DIVs Using CSS?

Susan Sarandon
Release: 2024-12-25 03:31:17
Original
311 people have browsed it

How to Create a Fluid Layout with Equally Spaced DIVs Using CSS?

Fluid Width with Equally Spaced DIVs

To achieve fluid layout with equally spaced DIVs, the following approach can be employed:

CSS

#container {
  text-align: justify;
  -ms-text-justify: distribute-all-lines;
  text-justify: distribute-all-lines;
}
Copy after login

This sets the text alignment to "justify," causing the content to be distributed evenly across the available width.

.box1,
.box2,
.box3,
.box4 {
  display: inline-block;
  vertical-align: top;
}
Copy after login

By setting display: inline-block, the DIVs will behave as inline elements, flowing horizontally within the container.

.stretch {
  width: 100%;
  display: inline-block;
  font-size: 0;
  line-height: 0
}
Copy after login

A "stretch" element is added to fill the remaining space and push the DIVs to their desired positions. Clearing the font and line height helps in some browsers.

HTML

<div>
Copy after login

The stretch element ensures that the DIVs are distributed evenly and responsively across the fluid container.

The above is the detailed content of How to Create a Fluid Layout with Equally Spaced DIVs Using CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template