Using auto-fit or auto-fill with CSS grid-template-columns can cause unexpected behavior and may not work as

I am currently working with this particular component:

<template>
  <div id="cms-img-upload-multiple" class="cms-img-upload-multiple">
    <input class="btn-upload" v-if="!state.images.length" type="file" @change="displayImage" multiple>
    <div class="img-wrap" v-else>
      <div class="img-loop-wrap" v-for="(image, index) in state.images">
        <div class="img-con-wrap" v-if="state.images[index]">
          <img class="img-display" :src="image">
          <fa class="cancel-icon" @click="clearDisplay(index)" :icon="[ 'fas', 'circle-xmark' ]"></fa>
        </div>
      </div>
    </div>
  </div>
</template>

This component is designed to manage the uploading and displaying of images within a cms. The images are organized within the img-wrap, which functions as a grid layout. Below is the corresponding scss:

.img-wrap {
  overflow: hidden;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  height: 80%;
  .img-loop-wrap {
    .img-con-wrap {
      display: flex;
      .img-display {
        width: 100%;
        height: 20vh;
        object-fit: contain;
      }
    }
  }

Currently, everything runs smoothly when the grid configuration is set as follows:

grid-template-columns: repeat(3, 1fr);

However, upon experimenting with changing it to either:

grid-template-columns: repeat(auto-fill, 1fr);

or:

grid-template-columns: repeat(auto-fit, 1fr);

The property grid-template-column fails to function and becomes disabled in the browser window, displaying an error message stating:

Invalid property value

Why is this occurring?

Answer №1

To achieve a responsive grid layout, consider using the properties auto-fill or auto-fit in combination with minmax. See the example below:

grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));

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

Update the displayed locations on Google Maps by fetching and displaying marker data

I am able to retrieve and display information from my MySQL table, but I need assistance with refreshing this data every 5 seconds using my current code. The data being shown is not extensive, just about 5 or 8 markers at a time. Below is the code I curren ...

Tips for creating a form-flip, similar to a card-flip effect, using web technologies

Looking to create a card flip effect similar to the one shown here. Once the sign up process is finished, the card will smoothly flip over to reveal the other side with a transitioning effect. ...

Exploring Next.js' dynamic routes with an alternative URL approach

Currently in the process of transitioning a React project to Next.js, I've encountered a minor issue with Dynamic Routing that doesn't seem to have any readily available solutions online. I have multiple information pages that utilize the same c ...

Utilize a jQuery selector to target the initial element of every alphabet character

I'm seeking some assistance with jQuery selectors and have a specific scenario that I need help with. Here is the HTML structure I am working with: <ul> <li class="ln-a"></li> <li class="ln-b"></li> <li cl ...

Saving user-generated inputs within a React.js component's state, focusing on securely handling passwords

Curious about forms in React.js? I don't have any issues, but I'm wondering if there are potential flaws in my approach. I've set up a basic form with two inputs for email and password: <input type="email" name="email" value= ...

What's causing the text not to wrap when using float?

I've tried setting float:left for the image and float:right for the text, but the image is still overlapping the text. What I really want is for the text to wrap around the image - to be on the right side of the image at the beginning and below the i ...

Can we consider JavaScript callbacks to be atomic?

Ensuring synchronization of fields in two independent third-party databases hosted in different locations is crucial to me. Below is a snippet of my generic node / express js code: router.post ('url', function(req,res,next) { third_party_ap ...

What is the best way to ensure balance between columns in Bootstrap 4?

Hello everyone! I am currently working on ensuring that all the columns in my table have equal width, except for the update and delete columns which should remain as they are. I'm utilizing Bootstrap 4.5.2 for this task. Below is the code snippet of ...

Changes in props do not automatically update children via Ref

I'm working on a React component that needs to update whenever the width changes: import { useRef, useEffect, useState } from "react"; function Child({ containerWidth }) { console.log("CHILD", containerWidth); return <div&g ...

Is it more beneficial to reference JavaScript libraries in individual user controls or in the master page when constructing a website?

Which of the following scenarios is most effective in terms of client-side (JavaScript) library referencing and loading? Assuming that the web solution is well-designed with components properly encapsulated Just to clarify, the master page mentioned coul ...

What is the best way to retrieve JSON data in a React application?

useEffect(async () => { const fetchPostData = async () => { const response = await axios("") setPosts(response.data) } fetchPostData(); }, []) Rendering : posts.map(post => <li>{post.name} ...

Curious about the power of jQuery methods?

I've been coming across codes similar to this: $(document.documentElement).keyup( function(event) { var slides = $('#slides .pagination li'), current = slides.filter('.current'); switch( event.keyCode ) { ...

Prevent redundant Webpack chunk creation

I am currently working on integrating a new feature into my Webpack project, and I have encountered a specific issue. Within the project, there are two entry points identified as about and feedback. The about entry point imports feedback, causing both abo ...

Utilizing PHP Variables in Ajax Calls: Transferring Data between JS and PHP

I've been struggling to grasp how to pass information from PHP to JavaScript and vice versa. I've spent an entire night trying to figure this out and would really appreciate it if someone could help me understand how to send two variables to an a ...

Creating input fields in a plugin that dynamically initializes multiple fields

I have multiple forms on a single page, each containing a phone number field driven by a JavaScript plugin. As a result, I am faced with having to properly initialize a large number of these fields. Manually initializing them would require: number of for ...

Unauthorized Access with Ajax jQuery

While working on an ajax request using Jquery, I encountered a dilemma. Even though the page is only accessible to logged in users, my cookies are not being sent along with the request. This results in a 401 error. I am already logged in, so why aren' ...

Exploring elements with Watir WebDriver and ExtJS

Currently, I am performing an acceptance test using watir-webdriver with Ruby. I have a question regarding ExtJs support with Watir webdriver. Is it possible to locate elements that are dynamically generated by ExtJS? I have attempted the following: @brow ...

The icon stubbornly refuses to budge to the right or keeps conflicting with the unordered list beneath it

I'm assuming that the empty space represents a div element, with some room on the right side. Based on what I see in the screenshot, I'm trying to move the Bars-Icon to the right corner of the div, at the top, and have the ul list below it. Howev ...

Delete the rows in a table's column

I used Bootstrap to create a table. The goal was to have a table with rows that have different background colors for each row. However, I'm facing an issue where there is spacing between the columns when separating the rows. How can I remove this sp ...

Using a Vue variable with a Laravel helper

Here is the route I have set up in my Laravel application: Route::get('/article/{id}', 'ArticleController@show')->name('article'); And this is how I'm using it in my Blade file: <a href="{{ route('article&ap ...