Home > Web Front-end > CSS Tutorial > How to Achieve Fluid Width and Even Spacing for Four DIVs in a Container?

How to Achieve Fluid Width and Even Spacing for Four DIVs in a Container?

Barbara Streisand
Release: 2024-12-30 11:57:10
Original
901 people have browsed it

How to Achieve Fluid Width and Even Spacing for Four DIVs in a Container?

Fluid Width with Equally Spaced DIVs

Question:

You have a fluid width container DIV with four DIVs, each with fixed dimensions. How can you float box 1 to the left, box 4 to the right, and space boxes 2 and 3 evenly between them, maintaining fluid spacing as the browser window size changes?

**Answer:

Refer to the provided JSFiddle for a complete example: http://jsfiddle.net/thirtydot/EDp8R/

Explanation:

This solution utilizes several techniques to achieve the desired layout:

  • text-align: justify;: This aligns the DIVs horizontally, distributing space between them.
  • .stretch: A span with width set to 100%. It expands to fill the remaining width of the container.
  • display:inline-block; *display:inline; zoom:1;: Ensures inline-block behavior for IE6/7.
  • font-size: 0; line-height: 0;: Prevents vertical space caused by inline-block in IE6.

By combining these techniques, the DIVs are positioned fluidly, evenly spaced and floating as desired, regardless of the container width.

The above is the detailed content of How to Achieve Fluid Width and Even Spacing for Four DIVs in a Container?. 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