<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: adrishy</title>
    <description>The latest articles on DEV Community by adrishy (@adrishy108).</description>
    <link>https://dev.to/adrishy108</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2991353%2F6cb63fba-0ff9-4fe5-96e1-f4e2510adce4.png</url>
      <title>DEV Community: adrishy</title>
      <link>https://dev.to/adrishy108</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adrishy108"/>
    <language>en</language>
    <item>
      <title>Fixing Grid Layout Overflow: Making a Grid Item Scrollable Without Breaking Everything</title>
      <dc:creator>adrishy</dc:creator>
      <pubDate>Sat, 29 Mar 2025 19:13:56 +0000</pubDate>
      <link>https://dev.to/adrishy108/fixing-grid-layout-overflow-making-a-grid-item-scrollable-without-breaking-everything-g1</link>
      <guid>https://dev.to/adrishy108/fixing-grid-layout-overflow-making-a-grid-item-scrollable-without-breaking-everything-g1</guid>
      <description>&lt;p&gt;``&lt;/p&gt;

&lt;p&gt;Ever built a grid layout only to see it break when content overflows? If you’ve been dealing with a stubborn grid item that expands beyond its assigned space, pushing everything else out of place, then you’re in the right spot. Let’s walk through the issue and fix it the right way.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;Imagine you’ve got a CSS Grid layout with a &lt;strong&gt;specific item that spans multiple rows&lt;/strong&gt;—like a transaction history panel. Inside that grid item, you’ve got a list of transactions that keeps growing. &lt;/p&gt;

&lt;p&gt;The problem? &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As the list grows, the grid item expands &lt;strong&gt;beyond its allocated space&lt;/strong&gt;, messing up your entire layout.&lt;/li&gt;
&lt;li&gt;Instead of keeping the grid item fixed and making the list scroll &lt;strong&gt;inside it&lt;/strong&gt;, the whole thing stretches like an unruly rubber band.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What We Want&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The grid item (let’s call it &lt;code&gt;.transaction-card&lt;/code&gt;) should &lt;strong&gt;stay within its assigned grid area&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The overflowing list inside it should &lt;strong&gt;scroll instead of pushing everything else down&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why Does This Happen?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;CSS Grid is great, but by default, &lt;strong&gt;grid items expand if their content overflows&lt;/strong&gt;. Even though you’ve defined &lt;code&gt;grid-row: 1 / span 3;&lt;/code&gt;, the grid item will still grow if there’s too much content inside it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The root cause?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The list inside the grid item &lt;strong&gt;has no height constraints&lt;/strong&gt;, so it pushes the entire &lt;code&gt;.transaction-card&lt;/code&gt; beyond its grid area.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Fix&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To solve this, we need to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Keep the &lt;code&gt;.transaction-card&lt;/code&gt; inside its grid area&lt;/strong&gt; by forcing it to always respect its height.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make the overflowing content scrollable inside&lt;/strong&gt; using &lt;code&gt;overflow-y: auto;&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The Correct Way to Do It&lt;/strong&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;HTML&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;html&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;Transaction Details&amp;lt;/h3&amp;gt;

  Transaction 1
  Transaction 2
  Transaction 3
  Transaction 4
  Transaction 5
  Transaction 6
  Transaction 7


+ CREATE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;CSS&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;css&lt;br&gt;
/* Define a grid with fixed row sizes &lt;em&gt;/&lt;br&gt;
.grid-container {&lt;br&gt;
    display: grid;&lt;br&gt;
    grid-template-columns: repeat(3, 1fr);&lt;br&gt;
    grid-template-rows: repeat(4, 1fr); /&lt;/em&gt; Keeps rows fixed &lt;em&gt;/&lt;br&gt;
    height: 100vh;  /&lt;/em&gt; Makes sure the entire grid has a fixed height */&lt;br&gt;
    gap: 10px;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;/* Keep the grid item inside its assigned space &lt;em&gt;/&lt;br&gt;
.transaction-card {&lt;br&gt;
    grid-column: 3;&lt;br&gt;
    grid-row: 1 / span 3;&lt;br&gt;
    display: flex;&lt;br&gt;
    flex-direction: column;&lt;br&gt;
    height: 100%; /&lt;/em&gt; Ensures it fills its assigned grid space &lt;em&gt;/&lt;br&gt;
    overflow: hidden; /&lt;/em&gt; Prevents it from growing beyond its limits */&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;/* Make the list scrollable inside the card &lt;em&gt;/&lt;br&gt;
.transactions-detail-wrapper {&lt;br&gt;
    flex: 1; /&lt;/em&gt; Fills available space inside .transaction-card &lt;em&gt;/&lt;br&gt;
    min-height: 0; /&lt;/em&gt; Critical to prevent flexbox from forcing growth &lt;em&gt;/&lt;br&gt;
    overflow-y: auto; /&lt;/em&gt; Enables scrolling when items exceed height */&lt;br&gt;
    padding: 10px;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;/* Button stays at the bottom, doesn't get pushed up &lt;em&gt;/&lt;br&gt;
.create-btn {&lt;br&gt;
    padding: 12px 20px;&lt;br&gt;
    background-color: black;&lt;br&gt;
    color: white;&lt;br&gt;
    border: none;&lt;br&gt;
    border-radius: 5px;&lt;br&gt;
    flex-shrink: 0; /&lt;/em&gt; Ensures the button doesn’t shrink */&lt;br&gt;
    margin: 10px;&lt;br&gt;
}&lt;br&gt;
&lt;code&gt;&lt;/code&gt;`&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why This Works&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The grid item stays put&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.transaction-card&lt;/code&gt; is forced to &lt;strong&gt;stay inside its assigned grid area&lt;/strong&gt; by setting &lt;code&gt;height: 100%&lt;/code&gt; and &lt;code&gt;overflow: hidden;&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The list scrolls instead of expanding&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.transactions-detail-wrapper&lt;/code&gt; takes the available space inside &lt;code&gt;.transaction-card&lt;/code&gt; without forcing it to grow.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;min-height: 0;&lt;/code&gt; (a &lt;strong&gt;common gotcha&lt;/strong&gt;) ensures that flexbox doesn’t let the list overflow its parent.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;overflow-y: auto;&lt;/code&gt; makes the list scroll when there’s too much content.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The button stays in place&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;flex-shrink: 0;&lt;/code&gt; makes sure the button at the bottom doesn’t shrink when the list overflows.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Final Thoughts&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This solution keeps the grid layout &lt;strong&gt;clean and structured&lt;/strong&gt; while ensuring that growing content is handled properly. If you’re ever struggling with an expanding grid item, check for these:&lt;/p&gt;

&lt;p&gt;✔ Does the parent have a &lt;strong&gt;fixed height&lt;/strong&gt;? (If not, the child will expand it.)&lt;br&gt;
✔ Did you add &lt;strong&gt;&lt;code&gt;min-height: 0;&lt;/code&gt;&lt;/strong&gt; inside a flexbox? (Without it, children might force growth.)&lt;br&gt;
✔ Are you using &lt;strong&gt;&lt;code&gt;overflow-y: auto;&lt;/code&gt;&lt;/strong&gt; correctly? (Otherwise, content won’t scroll.)&lt;/p&gt;

&lt;p&gt;Now your grid layout stays intact, and any overflowing content scrolls &lt;strong&gt;inside its section&lt;/strong&gt; instead of breaking everything! &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
