The grid item's content is spilling out of its container

I am experiencing an issue with a simple grid where the content of two grid items is overflowing and not staying within their designated areas.

Below is the code snippet I am using, which was partially inspired by this post:

body{ 
    background-color: #E3E3E3;

}
#six.container{
    display: grid;
    grid-template:
    [row1-start] "header header header" 40px [row1-end]
    [row2-start] "footer footer footer" 25px [row2-end]
    / auto 50px auto;
    background-color: #FFF3E8;

}

#six .item{
    text-align: center;
    border-radius: 5px;
    border: 1px solid #F78100;
    background-color: #F89426;
    margin: 5px;   
}
<h2>Grid 6</h2>
<div class="container" id="six">
    <div class="item item-1">item 1</div>
    <div class="item item-2">item 2</div>
    <div class="item item-3">item 3</div>
    <div class="item item-4">item 4</div>
    <div class="item item-5">item 5</div>
    <div class="item item-6">item 6</div>
</div>

It seems that item 2 and 5 are not displaying correctly within the grid.

Answer №1

The 2nd column's content is overflowing due to the fixed width of 50px you set with auto 50px auto. It cannot exceed 50px, leaving only 40px for content after considering the 5px margin.

To make the column size itself based on its content, consider using 1fr auto 1fr.

Below is an example using your code:

body{ 
    background-color: #E3E3E3;

}
#six.container{
    display: grid;
    grid-template:
    [row1-start] "header header header" 40px [row1-end]
    [row2-start] "footer footer footer" 25px [row2-end]
    / 1fr auto 1fr;
    background-color: #FFF3E8;

}

#six .item{
    text-align: center;
    border-radius: 5px;
    border: 1px solid #F78100;
    background-color: #F89426;
    margin: 5px;   
}
<h2>Grid 6</h2>
<div class="container" id="six">
    <div class="item item-1">item 1</div>
    <div class="item item-2">item 2</div>
    <div class="item item-3">item 3</div>
    <div class="item item-4">item 4</div>
    <div class="item item-5">item 5</div>
    <div class="item item-6">item 6</div>
</div>

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

Diagonal-left ending div in cascading style sheets

Looking to achieve a div with a diagonal side similar to the image in the link below: https://i.sstatic.net/u9grW.png I'm trying to figure out the best way to do this. One idea is to position 2 divs closely together and rotate one of them. Alternativ ...

Hide Table field display in HTML / ASP.NET

I have recently taken over a web application that was developed using ASP.NET. This app generates a table of query results from a database, with all fields appearing as text except for the "Url" column which is displayed as a hyperlink (see code below). If ...

Using CSS to place the h1 text on top of an image

I need some advice on how to place a heading above an image. I have tried using negative margin and adjusting z-index, but the image still covers the heading. If you have a better solution, please let me know! Thank you in advance for your help! PS: Anot ...

Swirling hues transforming into #000000 upon second attempt

My goal is to create a button that generates two random color codes. Initially, this button seems to work fine on the first click, but on the second click, both codes turn into #000000. Despite my attempts to troubleshoot the issue, I haven't been ab ...

Suggestions for incrementing a button's ID every time it is clicked

I am working on a button functionality that increases the button id when clicked. Below is the HTML code for the button: <input type="button" id="repeataddon-1" name="repeataddon" class="repeataddon" value="add" > Accompanied by the following scr ...

Switching the focus of detection from a child to a parent

I am currently working on enhancing the functionality of my UI to display selections dynamically as they are selected or de-selected. import { Wizard } from './report-common'; import { Router } from '@angular/router'; import { DataServ ...

"Stay informed with the latest updates on Wordpress through our

I am currently working on creating a static homepage with a newsfeed, but I only want to display the title and date posted. I considered using a widget, but I plan to integrate this news feed with a slideshow in the future and didn't want to limit my ...

Breaking content into two sections using Javascript or jQuery

Uncertain if Javascript can handle this task, any assistance or advice is appreciated. Consider this scenario: Suppose I have a 6-paragraph long content (text only) being pulled dynamically from the database all at once. This means that all 6 paragraphs a ...

Utilizing HTML/CSS with React/Bootstrap: A Comprehensive Guide

Looking for help with integrating HTML/CSS code into React/Bootstrap? I need assistance with coding in React using Bootstrap. How do I effectively use components and props? Even after installing bootstrap, I am encountering errors. Is it possible to dire ...

What is the best way to showcase all tab content within a single tab menu labeled "ALL"?

I have created a tab menu example below. When you click on the button ALL, it will display all the tabcontent. Each tab content has its own tab menu. Thanks in advance! function openCity(evt, cityName) { var i, tabcontent, tablinks; tabcontent = doc ...

Plotly Express Unleashes the Power of Subplots

After spending countless hours scouring the internet, I am feeling utterly frustrated and perplexed about how to deal with subplots using plotly express in Python. The concept is to create a line plot alongside a scatter plot and another line plot, where ...

Utilizing a Custom Validator to Compare Two Values in a Dynamic FormArray in Angular 7

Within the "additionalForm" group, there is a formArray named "validations" that dynamically binds values to the validtionsField array. The validtionsField array contains three objects with two values that need to be compared: Min-length and Max-Length. F ...

Using SASS to Access a Parent Class from a Child Element

In my experience with SASS, I encountered a problem. Here's an example of what I'm attempting to do: .message-error { background-color: red; p& { background-color: yellow } } Desired CSS output: .message-error { b ...

Syntax error: Your code encountered an unexpected closing curly brace

Here is the code snippet I am working with: <?php session_start();?> <!DOCTYPE html> <html> <head> <title>Narcis Bet</title> <meta charset="utf-8"> <link rel="stylesheet" href="css/style.css" type="text/css"&g ...

What is the procedure for selecting an element based on its child containing specifically filtered text?

Imagine a webpage with the following elements: <div data-search="type1"> any HTML <!-- .click is a child of any level --> <span class="click" data-source="page1.html">blue</span> <!-- let's call it "click1 ...

The functionality of Angular Datepicker is disrupted when scrolling through the page

Coding in HTML <div class="col-5 col-md-3 px-0 daterange-picker"> <div class="form-group"> <div class="input-group"> <input type="text" id="second ...

Crafting an interactive SVG element that maintains its clickability without interfering with mouseLeave events

Trying to Achieve: Changing color and displaying SVG when hovering over a row Clicking the SVG triggers a function, including external functions (not limited to ones defined inside script tags) Returning the row to its original form when mouse leaves Cha ...

The website is failing to load the script, CSS files, or Three.js

As a beginner with limited experience in HTML, JavaScript, and website creation, I apologize if my information is lacking. I am attempting to build a website using a 3D object from three.js. However, when uploading the site to Cpanel's live server, no ...

Retain the dashes in their original positions while extracting numbers following each dash from an array using Regex

Someone from a different discussion helped me figure out how to extract the numbers from an array. However, I am now struggling to capture the numbers after the "-" dash. Let me illustrate what I have and put you in the same scenario. Here is the array co ...

MEAN stack application that has an input field with a dynamic attribute which saves as undefined

How come the value for a dynamic attribute is showing up as "undefined" in my form? I initially thought it was related to a hidden input, but the issue persists even when the input is not hidden. When trying to save a new event, I want the user to be able ...