The dimensions of the box are not predetermined by the size of the photo

I'm attempting to develop a photo gallery that emulates the style of (using the Unsplash API -> )

However, the size of the container box does not adjust properly with the photos.

<div className="imageGrid__container">
    <div className="imageGrid__column">
        <div className="imageGrid__item">
            <img
                className="imageGrid__itemImage"
                src=""
            />
        </div>
        <div className="imageGrid__item">
            <img
                className="imageGrid__itemImage"
                src=""
            />
        </div>
        <div className="imageGrid__item">
            <img
                className="imageGrid__itemImage"
                src=""
            />
        </div>
    </div>
    <div className="imageGrid__column">>
        <div className="imageGrid__item">
            <img
                className="imageGrid__itemImage"
                src=""
            />
        </div>
        <div className="imageGrid__item">
            <img
                className="imageGrid__itemImage"
                src=""
            />
        </div>
        <div className="imageGrid__item">
            <img
                className="imageGrid__itemImage"
                src=""
            />
        </div>
    </div>
    <div className="imageGrid__column">
        <div className="imageGrid__item">
            <img
                className="imageGrid__itemImage"
                src=""
            />
        </div>
        <div className="imageGrid__item">
            <img
                className="imageGrid__itemImage"
                src=""
            />
        </div>
        <div className="imageGrid__item">
            <img
                className="imageGrid__itemImage"
                src=""
            />
        </div>
    </div>
</div>

CSS File :

.imageGrid__container {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
    gap: 30px;
    padding-left: 100px;
    padding-right: 100px;
}

.imageGrid__item {
    margin-bottom: 20px;
    border: 1px solid red;
    width: 100%;
}

.imageGrid__itemImage {
    width: 100%;
    background-size: cover;
    background-position: center center;
    object-fit: contain;
    background-repeat: no-repeat;
}

Can you pinpoint where I may have gone wrong?

Pardon the language used.

I've experimented with different approaches, but the issue persists.

Answer №1

When dealing with the spacing of inline and inline-block elements, it's important to understand how setting elements on a line can create extra space. One way to address this issue is by using display: block; for img tags or margin-bottom: -4px;.

For your situation, I recommend using display: block; as the solution.

For more solutions and further information, you can visit this link

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

What is the best way to test routing with Next JS using links?

As a newcomer to the NextJS environment and currently in the process of migrating an application from standard ReactJS, I am faced with a challenge regarding testing a link to another page. Can anyone provide some guidance on how I should refactor my test ...

How about implementing built-in validation for Vue Headless UI Listbox (Select) element?

I need assistance in integrating native validation support into the Vue3 or Nuxt 3 Vue Headless UI Listbox (Select) component. It appears that direct support is not available, so I am looking for the best and most straightforward approach to achieve this. ...

I have successfully implemented the Context API in my Next.js project and everything is functioning smoothly. However, I encountered an error while using TypeScript

Currently, I am working on a Next.js project that involves using the Context API. The data fetched from the Context API works perfectly fine, but I am encountering errors with TypeScript and I'm not sure how to resolve them. Error: Property openDialo ...

Leveraging a JQuery plugin to generate dynamic HTML content

Recently, I came across a fantastic JQuery plugin that Stack Overflow graciously provided for everyone to use :) Auto-size dynamic text to fill fixed size container However, I encountered a little challenge while trying to implement this on an HTML eleme ...

React and MaterialUI Chrome Extension - Data did not populate in the table

Currently, I am in the process of developing a browser extension. My main challenge lies in displaying data within a table that has been created using MaterialUI and React. Despite not encountering any errors, everything else renders perfectly. The console ...

Struggling to retrieve a JSON object from an Express and Node application, only receiving an empty result

Can anyone assist me? I'm having trouble with the res.json() function in my code. It seems to work after the first request, but not after the second. Right now, my application is quite simple - it scrapes user data from social media platforms like Twi ...

Is there a way to properly access and interpret a .log extension file within a React component?

import React from "react"; import "./App.css"; function FileReaderComponent() { const readLogFile = () => { if (window.File && window.FileReader && window.FileList && window.Blob) { const preview = document.getElementByI ...

What is the best way to ensure that a Material-UI Select remains open after clicking on a single item within it?

I've developed a customized Material-UI dropdown with an optional search/filter text field at the top to help users navigate through numerous entries. However, I'm facing an issue with keeping the dropdown open when clicking on the search field ( ...

The only information returned from calling mongoose's Model.save() method are the fields { _id, __

I've encountered a problem even though I believe I'm following all the right steps. I'm attempting to save an item from a form into my mongodb collection using mongoose. This is what my schema looks like: // stationmodel.js export const Sta ...

What is the best way to extract values from promises that are still pending?

Having some issues with the code below and unable to achieve the desired output. Any help in identifying what's wrong would be greatly appreciated. Thanks! Here is the code: // Making http requests const getJSON = require('get-json'); ...

Utilizing tag keys for inserting text and adjusting text sizes within a Web application

Creating an online editing interface for coursework where keyboard events are used. The goal is to have the tab key insert text, while also reducing the size of the text on that line. However, upon using getElementById, an error message pops up stating: ...

Having trouble changing the icon in Google Maps during the event?

Seeking guidance with Google API V3 as a newcomer. The task at hand is to switch the icon during a zoom event. Everything works smoothly except for the part where I need to detect the change in zoom and modify the icon from a basic circle to Google's ...

Modify the c3 axis labels using CSS

I've been using the c3 package in R, which serves as a wrapper for the C3 javascript charting library created by Masayuki Tanaka. One issue I encountered is that my c3 chart was cutting off the last date on the x-axis. After inspecting it in Chrome I ...

Is there a way to effectively incorporate window.clearInterval() into this javascript code to achieve the desired outcome

In my quest to create a pomodoro clock, I decided to experiment with window.setInterval() and its counterpart window.clearInterval before delving into actual coding. However, I've encountered an issue with getting window.clearInterval() to function as ...

Sidebar Masonry - Use Bootstrap for a Unique Layout

My goal is to have the page divided into 4 rows, with Masonry aligning the posts within 3 rows and a sidebar displayed on the right. However, I am facing an issue where Masonry mixes everything up and does not allow me to have a sidebar at the right. HTML ...

Initiate the React project by executing the command to start React Native development

Typically, I start my projects using npm start, but one time I accidentally ran npx react-native start and all the installation process for React Native completed. Now, I'm not sure if I need to worry about this or if I should remove React Native. If ...

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 ...

Express server and create-react-app build facing issues with Glyphicons and fonts functionality

Encountering an issue in the browser console: Failed to decode downloaded font "localhost:5000/static/media/fontname.@#$.woff" OTS parsing error: invalid version tag Came across some suggested solutions like adding a homepage:"./" to package.json. However ...

Building an Angular 4 app featuring a customized default landing page and URL parameters functionality

I am in the process of developing a web portal that will be embedded within an iFrame. Below is the code snippet I am using to set up the portal: Routes Configuration const routes: Routes = [ { path: '', redirectTo: '/dash ...

Initiate the process of displaying data on a datetime chart using Highcharts

I am currently developing a yearly chart, but I've encountered a small issue. The chart begins in January, however there is no data available until May. The client specifically wants the chart to only display when there is data available, and unfortu ...