Exploring the concept of overflow and minmax behavior in CSS grid

Summary: Example of overflow in nested grid layout on Codepen, and attempts to fix it using CSS

grid-template-columns: repeat(16, minmax(0,1fr));


Within the element called container, there are two main elements - summary-wrapper and stats-wrapper

The grid within the container is defined as follows:

.container {
    display: grid;
    grid-template-columns: repeat(16, 1fr);

    column-gap: 4rem;
    row-gap: 4rem;
    padding: 5rem;
    width: 100%;
}

The element summary-wrapper occupies grid-column: 1/11; (line 96) and stats-wrapper takes up grid-column: 11/17; (line 25)

Mentally changing the grid column of stats-wrapper to grid-column: 12/17 should simply move the start point of the element. This works in Chrome:

Chrome (no overflow):

https://i.sstatic.net/h6yQL.png

However, in Firefox:

https://i.sstatic.net/eTo5H.png

The differing behavior between browsers raises questions about my understanding of how grid containers function. Although this issue has been encountered before, following a fix for inputs, the problem persists with nested grids despite using

grid-template-columns: repeat(16, minmax(0,1fr));
(line 50) this time:

https://i.sstatic.net/8mI1H.png

The inability to understand why certain elements need to overflow remains perplexing. Even after attempting a fix using minmax(0,1fr), which supposedly ensures that items do not exceed their designated space, the issue continues to persist.

Puzzling over the situation, as the items stats__section--viewed, stats__section--applications, and stats__section--trend seemingly have no minimum size apart from their text content.

This conundrum leaves me at a loss!

Check out the codepen here

Any assistance would be greatly appreciated!

Answer №1

The issue causing the overflow stems from the column-gap declaration within the inner grid called .stats__content.

.stats__content {
  position: relative;
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  column-gap: 4rem; <----- MAIN CULPRIT
  row-gap: 3rem;
  background-color: white;
  padding: 2rem 0.1rem 0.1rem 0.1rem;
}

Since this gap is a fixed width and repeated 15 times (as gaps are only between tracks, not edges), it leads to an inevitable overflow in this scenario.

(4rem) * (15 gaps) = 60rem of rigid width

To address this, consider reducing the number of gaps or exploring alternative methods for spacing the elements.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adhering to a modular approach to design

I am facing an issue with two modules: One is the .master-header and the other is the .header-nav The .header-nav is contained within the .master-header and consists of a simple navigation menu: <nav class="header-nav"> <ul> ...

The div element is not expanding as expected, causing the content to overlap

In my code, I have a portfolio-container div with two images and paragraphs inside a list element. The issue I'm facing is that the div is not expanding vertically, causing the images and paragraphs to overlap with the footer below. I've attempte ...

What is the best way to implement an Android-style tab bar using Bootstrap for web pages?

Can you provide guidance on using Bootstrap to create an Android tab bar similar to the one seen in the WhatsApp application for web pages? Thank you for your assistance. ...

Stop the recurrence of multiple clicks by incorporating a Bootstrap modal popup confirmation

$('button[name="remove_levels"]').on('click', function (e) { var $form = $(this).closest('form'); e.preventDefault(); $('#confirm').modal({ backdrop: 'static', ...

"Learn an effective method for presenting JSON variable data in a Bootstrap modal with a clean design using three distinct columns

I have successfully loaded JSON data into my HTML page using JQuery. By clicking a button, I can trigger a bootstrap modal that displays the content of the JSON variable. However, there is an issue with how the JSON data is displayed. I need the data to b ...

The navigation bar struggles to display list elements without proper line breaks

Recently, I've been immersed in a web development project for a company. For the navigation bar, I opted to use the FlexNav JQuery plugin. While referencing the example on , I encountered an issue when attempting to add more than 5 list elements; they ...

Positioning Elements with CSS Relative and Absolute Placement

I am relatively new to the world of web design and currently grappling with the concept of positioning in CSS. I have a basic understanding of relative and absolute positioning for elements. In the code snippet below, there is a <div> that acts as th ...

Tips for showing a form's help text when manually rendering fields in Django forms?

In my Forms.py file, I have the following code snippet: class CustomerForm(forms.Form): name = forms.CharField(max_length=255,required=True,validators=[alphaonly],help_text="Enter your name") I am attempting to render it in an HTML format like ...

Employing ngModel in an option dropdown

I am having trouble passing an attribute from an API call to a submit function. I suspect it might have something to do with either the option select or how the input is being formatted. Encountering the error Error: No value accessor for form control wit ...

Update the image on a webpage by simply clicking on the current image

Hey there, I'm looking to implement a feature where users can choose an image by clicking on the current image itself. Here's my code snippet. The variable url holds the default image. My goal is to make the current image clickable so that when ...

Is it possible to create a dynamic <hr /> using Flexbox?

In the midst of working on my application, I managed to achieve a simple layout. However, there is one peculiar requirement that has been eluding me for the past 2 days and now I find myself in need of assistance. Here is the current HTML code I am workin ...

Integrating CSS into dynamically generated table rows using jQuery

Having trouble applying CSS to table rows created via ajax request. Despite using jQuery to add CSS to newly generated rows, it only affects the existing table headers. The table already has a 'sortable' class which also doesn't apply to dy ...

Play framework fails to apply style attributes correctly

When working with play-framework 2.3.x, I am in the process of creating a form and would like to show/hide it based on a model attribute. Typically, setting the style attribute manually using style = "display: none" and style = "display: block" works fine. ...

Achieve the sticky effect for text in a HTML div using CSS to keep it anchored to the

Seeking advice on how to create a floating box that remains in the bottom right corner of a div using CSS. Any tips or suggestions are appreciated! (Here's an example of what I'm aiming for: https://i.stack.imgur.com/DkD5C.png) ...

Adjust the properties within the component's styles using Angular 2

In this project, the objective is to dynamically change the background-color based on different routes. The goal is to display a specific color for UpcomingComponent while keeping the background-color consistent for all other routes. The approach involves ...

Embed a video within an image while ensuring it remains responsive on all devices

I have a picture that resembles something like this one My goal is to embed a video into it while maintaining its aspect ratio when the screen size is reduced. The responsive design should only affect the width since the image will be displayed in portrai ...

Exploring the wonders of Bootstrap 3 panels and stylish floating images

Is it possible to create a responsive design using Bootstrap 3 panel along with a floating image positioned next to it? I want the panel to seamlessly fit into the available space, without overlapping the image. Can anyone provide guidance on achieving thi ...

Tips for fixing the position without affecting the width

I'm trying to figure out how to keep my #header fixed in position without it expanding in width. Despite checking my code multiple times, I can't seem to identify the factor causing my header to become wider and shift downwards unexpectedly. I in ...

Guide to implementing onhashchange with dynamic elements

Hey there! I've encountered a problem with two select boxes on my webpage, each in different anchors (one on the page, the other in an iframe). What I'm trying to achieve is for the code to recognize which anchor it's in and then pass the se ...

Is there a way to stop my <pre> code from being displayed on the page?

Currently, I am utilizing the google code prettifier found at http://code.google.com/p/google-code-prettify/ This tool functions similarly to stack overflow by enhancing and highlighting syntax when a block of code is input. However, I have encountered a ...