Photos on Display are Misaligned

I'm currently in the process of developing a responsive photo gallery based on this tutorial. Within my project, there exists a component known as MemoryList which is defined as shown below:

import React from 'react';
import _ from 'lodash';

import {MemoryItem} from "./MemoryItem";

class MemoryList extends React.Component {

  renderItems() {
    return _.map(this.props.memory, (memory, index) => <MemoryItem key={index} {...memory}
                                                                   deleteFunc={this.props.deleteFunc}/>)
  }

  render() {
    return (
        <div className="image-row">
          <div className={'column'}>
            {this.renderItems()}
          </div>
        </div>
    )
  }

}
export {MemoryList}

In addition to the component, there's also a corresponding CSS file:

.image-row {
    display: -ms-flexbox; /* IE10 */
    display: flex;
    -ms-flex-wrap: wrap; /* IE10 */
    flex-wrap: wrap;
    padding: 0 4px;
}

/* Establish four equal columns placed alongside each other */
.column {
    -ms-flex: 25%; /* IE10 */
    flex: 25%;
    max-width: 25%;
    padding: 0 4px;
}

.column img {
    margin-top: 8px;
    vertical-align: middle;
}

/* Responsive design - switches to a two-column layout at 800px width */
@media screen and (max-width: 800px) {
    .column {
        -ms-flex: 50%;
        flex: 50%;
        max-width: 50%;
    }
}

/* Responsive design - stacks the two columns on top of each other at 600px width */
@media screen and (max-width: 600px) {
    .column {
        -ms-flex: 100%;
        flex: 100%;
        max-width: 100%;
    }
}

My goal is to have 4 columns of images, with each column being represented by a MemoryList. Each MemoryList receives an array of objects to generate a MemoryItem:

class MemoryItem extends React.Component {

  renderAction(){
    const profile = JSON.parse(localStorage.getItem('profile'));
    const memory_user = this.props.user;

    if (profile.username === memory_user){
      return (
          <button name={this.props.id} className={'btn btn-primary'} onClick={this.props.deleteFunc}>Delete</button>
      )
    }
  }

  render(){
    return (
          <img name={this.props.id} className={"img-thumbnail"} src={this.props.image_url} alt={'N/A'}/>
    )
  }
}

However, the MemoryLists are not positioning themselves adjacent to one another, but rather are aligning vertically. Any suggestions on what might be causing this issue?

Answer â„–1

It appears that the issue lies in the addition of padding and flex: 25% to the column. To prevent the fourth column from being pushed to the next row, you should subtract the padding and flex value from the width. Alternatively, you can use justify content to create even spacing as shown below:

.image-row {
    display: -ms-flexbox; /* IE10 */
    display: flex;
    -ms-flex-wrap: wrap; /* IE10 */
    flex-wrap: wrap;
    padding: 0 4px;
    justify-content: space-between;
}

.column {
    -ms-flex: 23%; /* IE10 */
    flex: 23%;
    max-width: 23%;
    padding: 0 4px;
}

For standard screens, the same principle applies for media queries—subtract the padding from the width:

/* Responsive layout - switches to a two-column layout instead of four columns */
@media screen and (max-width: 800px) {
    .column {
        -ms-flex: 48%;
        flex: 48%;
        max-width: 48%;
    }
}

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

Enhancing jQuery UI popups with custom styles and layout

Currently, I am working on a web application that relies heavily on jQuery. To create popup windows, I have integrated jQuery UI dialog along with jQuery UI tabs and jScrollPane for customized scroll bars. The overall structure of the application is as fol ...

Modify the color of CSS for all elements except those contained within a specific parent using jQuery

I have a color picker that triggers the following jQuery script: //event.color.toHex() = hex color code $('#iframe-screen').contents().find('body a').css('color', event.color.toHex()); This script will change the color of al ...

Using the same `node_modules` folder for multiple React applications

I've configured React using NodeJS following the instructions on this link As I dive deeper into learning React, I find myself working on multiple small projects. Utilizing create-react-app has its drawbacks: It takes time to create a new app (even ...

Scroll bar displayed on a non-editable text box

The TextArea is currently set to readonly mode using "ng-readonly," which is causing the scrollbar-thumb not to appear. It's important to note that I am not utilizing webkit in this scenario. Below is the HTML code being used: <textarea dataitemfq ...

Designing a dinner scheduler using React (MERN stack), looking to repurpose a module for inputting and modifying meals

In the process of developing a meal planning application, I am faced with the challenge of utilizing the same modal component for both adding and editing meals. The modal contains fields for name, ingredients, and the day of the week for meal preparation. ...

Eliminating border styles alters the overall appearance of the page

I'm encountering an issue with my HTML/CSS code here: CSS * { padding: 0; margin: 0; border: none; outline: none; } #container { margin: 10px auto 10px auto; width: 960px; background-color: #dddddd; border: solid 1px black; } #contai ...

Ensure the menu bar remains at the top of the page without using the position:

Check out this awesome fiddle here! My menu bar looks great at the top, but for some reason it won't stay in place when the user scrolls down. I've tried adding position:fixed to the CSS under the first #cssmenu, but it messes everything up. Her ...

Utilizing a constant in setting the slotLabelFormat

I am attempting to configure the slotLabelFormat options in a React TypeScript project When I directly set slotLabelFormat={{ hour: "2-digit", minute: "2-digit", omitZeroMinute: false, meridiem: "short" }}, TypeScript compile ...

Encountering issues with the routing in my live Node.js project: ERROR

I am encountering issues with my project in production. I suspect it could be due to a misconfiguration or something similar. Could you please review the provided code snippets and see if you notice any potential issues? The project works fine locally, bu ...

What are the best practices for integrating FontAwsome Icons into a Hyperstack project?

How can FontAwsome Icons be effectively utilized in a Hyperstack project integrating Rails and ReactJS, while utilizing Yarn to selectively include the necessary icons? ...

How can we avoid re-rendering the same component repeatedly when using React Router v6?

As a beginner in react, I'm facing an issue with preventing components from re-rendering when navigating to a different page. Specifically, I want to display only text on my Signup and Login pages, but the Navbar keeps re-rendering every time I switch ...

Loading SVG images in advance

I am in possession of around one hundred simple SVG images, distributed among five different image folders. These images are currently retrieved on demand when they need to be displayed, which generally works well but occasionally results in flickering tha ...

Challenges arise when using CSS Grid to design a basic layout with rows and several centered divs

As a CSS Grid beginner, I am working on creating a simple layout for my personal blog using codepen.io Visit my codepen.io project here I aim to have multiple rows with full width, each containing various divs of different widths centered within the row. ...

NextAuth asynchronous function completion occurring before value is returned

When signing in, I am working on querying FirestoreDB and then retrieving the user data or null. I have attempted to use async await for this purpose, but the dependent code executes before the database query is complete. This issue is evident when "CORRE ...

What is the best way to emphasize a row in an Angular Material table based on a

I am facing an issue with highlighting row colors conditionally in my code. Although there are no errors, the background color is not being applied to the rows as expected. I have a total of 5 rows with the 'riskIndex' value set to 'H'. ...

Circle a component around another on the vertical axis (z-index)

A plugin caught my eye some time back, but I'm having trouble locating it. This nifty tool operates by positioning an element behind another one, then smoothly sliding it to the right. After that, it changes the z-index so the element appears larger i ...

The problem I'm facing with the space-between property in my flexbox list

I am working with a list ol that contains items styled as shown below: ol { display: flex; flex-flow: row wrap; justify-content: space-between; width: 400px; } li { width: 120px; height: 120px; } DEMO Currently, I have 3 it ...

The declaration file for the module 'tailwind-scrollbar' could not be located

Currently, I am in the process of utilizing Tailwind packages for a Next.js application, however, I have encountered an issue that has proved to be quite challenging to resolve. Every time I attempt to add a "require" statement to my tailwind.config.js fil ...

"Exploring the concepts of React Redux and the power

I am curious as to why there is no information available on how to integrate Redux with inheritance. For instance, if I have a base component: class BaseComponent extends Component{ } and all other components extend BaseComponent: class Todo extends Ba ...

Issues with Bootstrap's hamburger menu not functioning properly when clicked

Can't seem to get my hamburger button working. I've followed the bootstrap documentation and ensured that Bootstrap and jQuery are in the correct order, but still no luck. Any suggestions on what could be causing this issue? Are my links misplace ...