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.

https://i.sstatic.net/1PAQF.jpg

<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

Adding images to .xsl using XML

I have created a unique "blog" using XML and XLST. The format of the blog is as follows: <post id="1" category="Miscellaneous"> <ptitle>MiG-21</ptitle> <psubtitle>Mikoyan-Gurevich MiG-21</psubtitle> <image></image& ...

Guide on launching a mobile application upon clicking a button in a mobile browser (with the assistance of JavaScript/React) [Utilizing Deep Linking]

My goal is to create a functionality where, on a mobile browser, when the user clicks on a button: If the app is already installed on the user's mobile device, it should open up. If the app is not yet installed, I aim to redirect the user to the appr ...

Switching Tabs When a Button is Clicked

I am currently using a guide from the link provided to learn how to create tabs: http://www.w3schools.com/howto/howto_js_tabs.asp. function openTab(evt, tabName) { var i, tabcontent, tablinks; tabcontent = document.getElementsByClass ...

Updating a marker's latitude and longitude using Laravel, Google API, and Ajax: A step-by-step guide

I'm struggling with sending the marker coordinates to a controller using ajax. I have named my routes 'update-marker-position' and included csrf_token(), but I am still seeing an error message in the logs. In my web.php file: Route::post(&a ...

Employing the react Modal feature to create a versatile pop-up window that can be activated from numerous pages within

I have a Modal that is activated by various buttons spread across different components. I've managed to make it functional on the pages by passing variables in the Layout as shown below: const index = () => { const [show, setShow] = useS ...

SweetAlert html is not recognizing ng-app, but it functions correctly within the html body

When inserting a bootstrap table inside a SweetAlert, I encountered an issue where using ng-app or ng-repeat to populate data inside the table's rows did not call ng-app. However, when populating the table outside of the SweetAlert in the body, ng-app ...

Issues with scrolling divs not properly reaching the bottom of the content

I am facing an issue with 2 scrolling divs (outlined in red) that refuse to scroll to the bottom. I cannot seem to pinpoint what needs to be adjusted to resolve this problem. The thick outlined box represents a simulated browser window. View the code her ...

Angular 14 troubleshooting: Issues with using getRawValue() in IndexOf function

In this scenario, I have a straightforward Person interface defined as: import { FormArray, FormControl, FormGroup } from '@angular/forms'; import { Address } from './address'; export class Person { id: FormControl<number>; n ...

Unable to retrieve custom date picker value with React Antd

I have implemented a custom datepicker for entering dates in the 'MMDD' or 'MMDDYY' format. The date value is stored in state and used in the datepicker component as a controlled component. However, upon form submission, the datepicker ...

Solving the issue of .css being blocked due to MIME type while building tailwind is a common problem faced by

https://i.stack.imgur.com/nrDgJ.png While working on my tailwind CSS project, I ran npm run build. However, upon opening the built index.html file, I noticed that the CSS file was not loading properly. How can I resolve this issue? I am unsure of what st ...

Navigating using Backbone Marionette URL to Server Endpoint

I need to implement client-side validation to check if the user is logged in, and if not, redirect them to the sign-in page. The issue is that the sign-in page exists outside of my Backbone Marionette app. Is there a way in Marionette, Backbone, jQuery, or ...

Can data from an Angular app be accessed by an external JavaScript code within the same project?

I've been thinking about a theoretical scenario that luckily I haven't encountered yet. Imagine I have an Angular Project compiled in My PROJECT FOLDER. <br/> Inside this PROJECT FOLDER, there's another JAVASCRIPT FILE external to ...

Ensuring uniform height of columns in Bootstrap

I want all columns following the first row with col-md-6 to have equal height, regardless of dynamic content (go to full page). <html> <head> <title>Page Title</title> <meta charset="utf-8"> <meta name="viewport" ...

What are some ways to get Angular2 up and running in a newly created distribution directory?

Trying to setup my own Angular2+Typescript (+SystemJS+Gulp4) starter project has hit a roadblock for me. I encountered issues when transitioning from compiling TypeScript in the same folder as JavaScript with access to the node_modules folder, to organizin ...

Validation of default values in contact forms

Obtained a free contact form online and hoping it works flawlessly, but struggling with validation for fields like "Full Name" in JS and PHP. Here is the HTML code: <input type="text" name="contactname" id="contactname" class="required" role="inpu ...

Issue with Bootstrap modal not displaying in the center as expected

screenshot of the page Hey there, I'm struggling to understand why this modal is displaying incorrectly. I copied the code from the bootstrap website. Here it is: <button type="button" class="btn btn-info btn-lg" (click)="showPerformedActivityMod ...

Retrieving input data from FormSubmit command

I have implemented Formsubmit to manage forms on my websites, but I do not want users to be redirected to another page when submitting the form. My website is hosted on Netlify and when I tested the forms, I did not receive the information in my email. I a ...

I am experiencing difficulties with using the Material-UI Select component in NextJS

I am currently utilizing Material UI Select with Next.js and encountering some persistent errors on the page that I can't seem to resolve. You can view the errors in the following screenshot: https://i.sstatic.net/pIOvm.png Here is the code snippet i ...

Connecting queries in php

I am looking to connect searches from a checkbox form together. For example, if I select checkboxes a and b, I want the search results to display two different outcomes. <form role="form" action="R.php" method="post"> <div class="form-group"&g ...

Stopping the papaparse streaming process once a certain number of results have been achieved

Currently, I am utilizing the PapaParse library to parse a large CSV file in chunk mode. During my data validation process, I encountered an issue where I was unable to stop streaming the data once validation failed. I attempted to halt the streaming by ...