What could be the reason for the ineffectiveness of grid-auto-columns?

I've been delving into the world of CSS Grid Layout and I'm facing a puzzling issue. Despite using both grid-auto-columns and grid-template-columns, I haven't seen any changes reflected.

I've experimented with different values for grid-auto-columns but nothing seems to make a difference.

Why is this happening?

* {
  box-sizing: border-box;
}

.wrapper {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(3, 1fr);
  grid-auto-columns: 50px;
  grid-auto-rows: 200px;
  grid-gap: 20px;
}

.wrapper>div {
  border: 2px solid rgb(233, 171, 88);
  border-radius: 5px;
  background-color: rgba(233, 171, 88, .5);
  padding: 1em;
  color: #d9480f;
}
<div class="wrapper">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
  <div>7</div>
  <div>8</div>
  <div>9</div>
  <div>10</div>
</div>

Answer №1

Short Response

The reason why grid-auto-columns is not having any impact is due to the lack of columns in the implicit grid.


Clarification

In the realm of CSS Grid Layout, there exist explicit and implicit grids.

An explicit grid is one that you define explicitly. This type of grid is created when using properties such as:

  • grid-template-rows
  • grid-template-columns
  • grid-template-areas
  • grid (which encompasses the above three properties, and more)

Despite not being limited to confining grid items within the explicit grid, you can place items anywhere including outside this designated area, which leads to the concept of the implicit grid.

The implicit grid emerges from automatically generated rows and columns required to accommodate items positioned beyond the confines of the explicit grid.

While grid-template-columns and grid-template-rows dictate the size of explicit tracks, grid-auto-columns and grid-auto-rows determine the size of implicit tracks.

Upon reviewing your code, it reveals two columns and three rows within the defined explicit grid.

.wrapper {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(3, 1fr);
  grid-auto-columns: 50px;
  grid-auto-rows: 200px;
  grid-gap: 20px;
}

The three explicit rows share an equal distribution of free space (1fr). Additional rows will be set at a height of 200px.

The two explicit columns also take up an equal allocation of free space, with additional columns sized at 50px width.

However, with only two columns present in your code and no columns beyond the explicit grid boundaries, the grid-auto-columns property fails to have any effect.

Below are definitions for these types of grids according to the specification:

7.1. The Explicit Grid

The triplet of grid-template-rows, grid-template-columns, and grid-template-areas collectively outline the explicit grid within a grid container.

The grid shorthand provides a convenient way to configure all three simultaneously.

If grid items extend beyond the explicit grid, implicit tracks are introduced, characterized by the grid-auto-rows and grid-auto-columns properties.


7.5. The Implicit Grid

The properties grid-template-rows, grid-template-columns, and grid-template-areas establish a fixed number of tracks defining the explicit grid.

If grid items surpass these bounds, the grid container generates implicit grid tracks via the addition of implicit grid lines.

Together with the explicit grid, these lines constitute the implicit grid.

The grid-auto-rows and grid-auto-columns properties determine the size of these implicit grid tracks.

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

The right column in a relatively positioned layout descends as an element in the left column is revealed

Currently in the process of constructing a registration form for our website, everything is going smoothly with one minor hiccup. The form consists of two columns where users enter their information. Initially, when designing elements for the first (left) ...

CSS Background Image Properties

I'm struggling to display a background image on my HTML page. The image is saved in the same folder as the HTML file. <html> <head> <link rel="stylesheet" type="text/css" href="style/indexstyle.css" > <meta charset="ISO-8859-1"& ...

Tips for centering content in the middle of a line

How can I center align 3 buttons on a line using CSS and HTML? This is what I have tried so far: 1/ CSS : .center-buttons { display: flex; justify-content: center; } .button { margin: 0 10px; } 2/ HTML: <div class="row"> <di ...

Dynamic Divider for Side-by-Side Menu - with a unique spin

I recently came across a question about creating responsive separators for horizontal lists on Stack Overflow While attempting to implement this, I encountered some challenges. document.onkeydown = function(event) { var actionBox = document.getElementB ...

What is the best way to retrieve information from a webpage I have created using an express backend and an HTML frontend

I designed a login page named index.html that prompts users to enter their email and password, followed by a submit button with the label "Log In": <input type="submit" value="Log In" id="loginbutton"> Within my app.js ...

I'm puzzled as to why the hidden input field consistently returns the same value every time

As a beginner in php, I am facing an issue where I cannot trace the correct value of the hidden input which represents the ID of the image in the products table. Every time I try to delete an image, it always returns the ID of the last image in the product ...

Magento theme installation on the website encountered unexpected obstacles

Hi everyone, I'm currently in the process of constructing a website with Magento. However, I've encountered some issues after trying to install a theme. It seems like certain files, including CSS, are not loading properly. To provide better conte ...

To fill the remaining white space, add an underline after the last line of text

I'm struggling to implement a SCSS/CSS styling concept where I need to add a solid line before or after the last line of a heading. The challenge is that the width of the last line varies based on the screen size. I am open to any suggestions. Here&a ...

Flexbox problem - uneven heights

I have set up a flex box layout and you can view the codepen link here:- https://codepen.io/scottYg55/pen/zYYWbJG. My goal is to make the pink backgrounds in this flexbox 50% of the height, along with the background image so it resembles more of a grid sy ...

Ways to adjust the number of columns in a div using Bootstrap for varying screen sizes of larger devices

https://i.sstatic.net/1nHlm.pngI am new to coding and exploring html, css, and bootstrap. Is it possible to assign varying numbers of columns to a div based on different resolution ranges for larger devices? Specifically looking at the "lg" range which co ...

Filtering a section of the HTML using Ajax and jQuery

Dealing with an Ajax call in jQuery that's delivering a lot of unexpected HTML content. I'm attempting to extract the specific part I need, but the console is showing an empty string. Can anyone provide guidance on resolving this issue? $.ajax({ ...

Retrieve the content of the second <li> element using jQuery

Seeking assistance with replacing the separator symbol in a given structure. In order to proceed, I first need to identify its position. Can anyone offer guidance on how to do this? Below is the structure in question: <div> <ul> ...

Using the bootstrap CSS file causes my document to shrink in size when I convert it from HTML to PDF using iTextSharp in C# Winforms

I am working on developing a unique PDF export form using HTML and bootstrap that can be utilized in any C# project. My goal is to integrate bootstrap designs into my customized PDF layouts. While my own custom CSS file works perfectly, incorporating the b ...

Click the mouse to create a unique path from the list items within the <ul> <li> using jQuery

My current listing contains various files and folders: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fon ...

Retrieve all parent elements from a document using Nokogiri

I have a document structured as follows: <DL><a lot of tags>...<H3>Entry 1</H3><a lot of tags>...</DL> <DL><a lot of tags>...<H3>Entry 2</H3><a lot of tags>... <DL><a lot of ta ...

The modal box should adjust its height to perfectly accommodate the content within

I'm in the process of developing a straightforward modal (popup) window, using as few lines of code as possible... just the basics. The modal has a maximum width of 650px and its height adjusts to fit the content. In case the content exceeds the avai ...

Unable to send email through Ajax/PHP contact form

It's quite amusing that it worked perfectly for one evening. After reaching out to my host, they assured me that there should be no issues with it not working. I even tried testing it in Firebug, but it appeared to be sending successfully. Additionall ...

Ways to prompt rerendering in child components?

Currently, I am initializing child components within the parent and storing them in an array. I pass a function into the children's props that retrieves state. <QuestionContainer error={ () => this.state.currentError } /> The issue ari ...

Having difficulty sending a value with %45 to a REST API

Currently, I'm encountering an issue within my ASP.NET MVC 5 application. The problem arises when I send the following JSON data to a third-party API, which includes a password field: "{\"operation\":{\"Details\":{\"RESOURCE ...

Developing dynamic DOM layouts using prepend and append methods

I am looking to dynamically create the following structure using jQuery: <div id="mainWindow"> <div id="webgl"> <div id="global-ui"> <div id="gui"></div& ...