Fixed vs Flexible Layouts: Content-Based Sidebar Width with CSS Grid

This article demonstrates how to replace percentage-based two-column layouts with a fixed-width sidebar (180px) and flexible main area (1fr) using CSS Grid, ensuring navigation text remains readable while maximizing space for pipeline content during window resizing.

Cilantro Loves Linux
Cilantro Loves Linux
Cilantro Loves Linux
Fixed vs Flexible Layouts: Content-Based Sidebar Width with CSS Grid

1 Requirements

The goal is to add a project sidebar to the pipeline detail page. When the window widens, the main content should gain the extra space while the sidebar keeps a width suitable for navigation text.

2 Initial Implementation

The first version used a two-column layout with the sidebar taking 34% of the container and the main content using the rest. The sidebar contained project entries; the main area displayed pipeline information.

Initial interface
Initial interface

Figure 1: Sidebar width changes proportionally with the container.

3 Problem Analysis

3.1 Main Issues

When the window widens, the sidebar continues to grow even though the menu text does not increase; that space could be used for the pipeline main body. When the window narrows, the sidebar may shrink below a readable width for the text.

The percentage relationship expresses that both columns scale together, but it does not describe each area's content needs.

3.2 Design Principles

Areas that need to scale together can use proportions. Areas with stable content requirements should have their width determined by content first, letting other areas take the remaining space.

Cards with known suitable widths can also set a maximum width and shrink only when space is insufficient. This discussion focuses on layout decisions; CSS Grid can still be used to implement the fixed-and-flexible combination.

4 Optimized Implementation

4.1 Area Responsibilities

In this example the sidebar is set to 180px, and the main content uses the remaining space. The 180px is chosen after confirming that navigation text is readable at the target font size, then verifying that the main area can accommodate stages and run information.

Card interiors can still arrange their own column widths based on content; they do not need to share the outer navigation's proportion.

4.2 CSS Implementation

.project-layout {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 18px;
}
.project-main { min-width: 0; }
min-width: 0

allows the main area to shrink, but it does not automatically handle long strings inside. Artifact URLs still need wrapping; tables can adopt controlled scrolling depending on use case.

4.3 Narrow-Screen Switching

Continuously narrow the window and observe where the menu, stages, and actions start to not fit; then decide when to fold the menu or change the arrangement.

180px is the content-based width for this example; it does not mean every screen must force the same sidebar width. After switching on narrow screens, also verify navigation accessibility and current-location indication.

5 Effect Verification

Adjusted interface
Adjusted interface

Figure 2: Sidebar width determined by content; main area grows flexibly.

The images show the allocation change on the same canvas; the responsive behavior must be verified on the actual page.

☐ On wide screens, most new space goes to the main content.

☐ Menu text displays normally at the current sidebar width.

☐ Narrow-screen switching and long-address handling do not cause whole-page horizontal overflow.

6 Application & Practice

Continuously adjust the pipeline page width and record where the menu, run table, and deployment cards each start to break.

Deliver a region-division diagram that marks fixed widths, flexible widths, maximum widths, and switching conditions, and explains how each relates to the content.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

frontend developmentCSS GridUI designresponsive layoutfixed widthflexible widthminmaxsidebar
Cilantro Loves Linux
Written by

Cilantro Loves Linux

Focused on Linux system operations and maintenance technology exchange, regularly publishing in-depth technical articles covering core areas such as system architecture, performance optimization, and security hardening. Whether you are a beginner or a seasoned expert, you can find valuable resources to enhance your skills and solve problems here. Follow us to explore the mysteries of Linux operations!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.