Home > Web Front-end > CSS Tutorial > How Can I Create a Three-Column Flexbox Layout with Fixed-Width Side Columns and a Flexible Center Column?

How Can I Create a Three-Column Flexbox Layout with Fixed-Width Side Columns and a Flexible Center Column?

Barbara Streisand
Release: 2024-12-07 16:12:15
Original
732 people have browsed it

How Can I Create a Three-Column Flexbox Layout with Fixed-Width Side Columns and a Flexible Center Column?

Maintaining Fixed Width Columns with Flexible Center

You are seeking to design a flexbox layout with three columns, where the left and right columns maintain a fixed width, while the center column expands to occupy the remaining space. Despite setting dimensions for the columns, they undesirably shrink as the window size adjusts.

Solution

To achieve your desired layout, replace the width property with the following flex specification for the fixed-width columns:

flex: 0 0 230px;
Copy after login

This specification signifies:

  • 0 for flex-grow: do not expand the column.
  • 0 for flex-shrink: do not compress the column.
  • 230px for flex-basis: set the initial width to 230px.

In essence, this configuration ensures that the columns remain at 230px regardless of the window size.

Additional Feature

Regarding your additional requirement to conceal the right column based on user interaction, while maintaining the fixed width of the left column and expanding the center column accordingly, you can incorporate the following:

.column.center {
  flex: 1 0 calc(100% - 230px);
}
Copy after login

This modification ensures that when the right column is hidden, the center column fills the remaining space while the left column remains fixed at 230px.

The above is the detailed content of How Can I Create a Three-Column Flexbox Layout with Fixed-Width Side Columns and a Flexible Center Column?. 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