Menu

A CSS Grid Column Set to 1fr Still Overflows? The Minimum Is Not Zero
📰

A CSS Grid Column Set to 1fr Still Overflows? The Minimum Is Not Zero

DEV Community: frontend·Pixel Recruiting LLC·1 day ago
#fT8mU4Fi
#devtofrontend#devto#dev#min#column
Reading 0:00
15s threshold

We built a simple two-column page. The side menu had a fixed width. The main column was 1fr , which we read as "take whatever width is left." Then we put a long, unwrapped line of code in the main column. The page grew a horizontal scrollbar. The main column was wider than the leftover space. The 1fr did not shrink.

This is a CSS Grid issue. It is close in spirit to a flex item's automatic minimum, but the property that surprises people here is the track size itself.

The layout

<div class = "page" > <nav class = "side" > Menu </nav> <main class = "main" > <pre> npm install some-long-package-name-and-then-another-one </pre> </main> </div>

Enter fullscreen mode

Exit fullscreen mode

.page { display : grid ; grid-template-columns : 120px 1fr ; width : 400px ; }

.main pre { margin : 0 ; white-space : nowrap ; }

Enter fullscreen mode

Exit fullscreen mode

The page is 400 pixels wide. The menu is 120 pixels. You would expect the main column to be the rest, about 280 pixels.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.