Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
CSS

CSS: Fix a Subgrid That Ignores Its Parent Grid’s Track Sizes Because display: subgrid Was Only Set on One Axis

- 15.10.26 - ErcanOPAK

🎨 The Subgrid That Built Its Own Tracks Anyway

CSS Grid Level 2 lets a nested grid inherit its parent’s column or row tracks with grid-template-columns: subgrid, but that keyword only applies to the axis you actually set it on – the other axis defaults to behaving like an ordinary, independent grid unless you explicitly subgrid it too. Set it on columns and forget rows, and the child aligns its columns to the parent perfectly while its rows size themselves with no relationship to the parent at all.

🔎 The Problem

.parent {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, 80px);
}

.child {
    grid-column: 1 / 5;
    grid-row: 1 / 4;
    display: grid;
    grid-template-columns: subgrid; /* inherits parent's columns */
    /* grid-template-rows was never set to subgrid - this
       axis silently falls back to an ordinary grid with its
       own auto-sized rows, unrelated to the parent's 80px
       row tracks the rest of the layout is aligned to. */
}

✅ Fix: Set subgrid Explicitly on Every Axis That Needs It

  • Set grid-template-rows: subgrid alongside grid-template-columns: subgrid whenever the child needs to align on both axes – there’s no shorthand that applies subgrid to both at once, each axis has to name it independently.
  • If you only need one axis to inherit the parent’s tracks (columns aligned, rows free to size by content), that’s a legal and often intentional combination – just be certain you meant to leave the other axis independent, rather than having simply forgotten to set it.
  • Check support before relying on this for layout-critical alignment – subgrid shipped later than the rest of Grid Level 1 across browsers, so confirm your target browser matrix actually supports it before the parent/child alignment becomes something users depend on.

⚠️ Why This Is Easy to Miss

  • Nothing throws an error or a warning – an axis that isn’t subgridded is simply valid, ordinary grid behavior on its own, so DevTools shows a perfectly normal-looking nested grid with no indication that one axis was supposed to inherit and didn’t.
  • The misalignment is often subtle rather than dramatic – rows that are close to the parent’s sizing by coincidence can look almost right, which makes the bug easy to sign off on in a quick visual check and only notice later at a different viewport size or content length.

Subgrid doesn’t inherit the parent’s layout – it inherits exactly the one axis you named, and leaves the other to fend for itself.

— UI Engineer

Related posts:

CSS: Fix Elements That Ignore max-width Because of a Missing box-sizing Reset

CSS: Fix Elements That Ignore max-width Because of a Missing box-sizing Reset

CSS: Use Pseudo Classes for Interactive UI

CSS: Use Pseudo Classes for Interactive UI

CSS: Use text-wrap: balance for Better Heading Line Breaks

CSS: Use text-wrap: balance for Better Heading Line Breaks

Views: 8

Post navigation

WordPress: Fix a Site Health Critical Issue Because Loopback Requests Fail After Migrating to a New Host
C#: Fix a TaskCompletionSource Deadlock Caused by a Continuation That Runs Synchronously on the Thread Calling SetResult

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com