I am dealing with a set of divs wrapped in a flex container that tend to overlap each other. Their heights vary and sometimes they wrap multiple times. Any suggestions on how to prevent this

I am encountering an issue where the width of the div remains the same after it has wrapped, causing overlapping. I want the first div to push the second to the right and so on.

When I add a 100% width, it makes the width for the smallest div the same as the largest, leaving space on either side.

The columns are iterated over using {orderedColumns.map((column, index) => { return ( ); })}

<div style={{ display: "flex" }}>
       <div
         style={{
           height: "60px",
           display: "flex",
           flexDirection: "column",
           flexWrap: "wrap",
           overflowX: "visible"
         }}
       >
         <div>Test1</div>
         <div>Test1</div>
         <div>Test1</div>
         <div>Test1</div>
         <div>Test1</div>
       </div>
       <div
         style={{
           height: "60px",
           display: "flex",
           flexDirection: "column",
           flexWrap: "wrap",
           overflowX: "visible"
         }}
       >
         <div>Test2</div>
         <div>Test2</div>
         <div>Test2</div>
         <div>Test2</div>
         <div>Test2</div>
         <div>Test2</div>
         <div>Test2</div>
         <div>Test2</div>
         <div>Test2</div>
         <div>Test2</div>
         <div>Test2</div>
         <div>Test2</div>
       </div>
       <div
         style={{
           height: "60px",
           display: "flex",
           flexDirection: "column",
           flexWrap: "wrap",
           overflowX: "visible"
         }}
       >
         <div>Test3</div>
         <div>Test3</div>
         <div>Test3</div>
         <div>Test3</div>
         <div>Test3</div>
       </div>
     </div>

If you have any suggestions, they would be greatly appreciated.

Thank you.

Answer №1

When working with Flexbox columns, the parent's width remains constant even when items wrap, which may be causing your issue. For more information, you can refer to this discussion on Stack Overflow: When flexbox items wrap in column mode, container does not grow its width.

It seems unlikely that you'll achieve the desired layout using flexbox columns since the parent element cannot accurately determine its width due to this limitation.

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

Mastering the art of positioning images using CSS and HTML in email marketing

Currently in the midst of designing an email template for a new project. I have set up a table, with one row featuring some stripes and the next row showcasing a black bar to match the site's layout. My question is: Is there a way to incorporate an i ...

aligning columns within a flexible element that has a maximum height

Within this flex element, I have set flex: column wrap; and max-height: 150px;. The issue I'm facing is that justify-content doesn't seem to be working. However, when I switch to using height: 150px, the alignment works fine. This problem arises ...

Using two body tags in the code of a Wordpress site can lead to malfunctioning

I've encountered a strange issue with my Wordpress sites hosted on BlueHost. There seems to be a double <head> tag appearing in the HTML code, even though there is only one. This duplicate tag is causing issues with the proper rendering of the s ...

Load CSS styles once the HTML content has been generated by the PHP script

One way to dynamically add a section of HTML during page load is by making use of PHP in the index.php file: In your index.php file, you can include a section like this: <html> <head> <link href="css/style.css" rel="stylesheet"> ...

Determining the best scenarios to utilize Redux for fetching data from an API call

I decided to incorporate Redux into my project for managing state, along with using Axios for handling API requests. One question that arises is when should I make API calls through Redux actions and when should I directly call the API in a component? Do ...

Issue: The left property of the ForIn statement is null

Today, I encountered an issue after updating my react babylon app with react-scripts. Upon upgrading to babylon version 4.1.0, I started getting this error message: ./node_modules/babylonjs/babylon.js TypeError: /git/proconf_sa/node_modules/babylonjs/ ...

What could be the reason for the error message "module 'msw' does not export a member named rest" when trying to import "import { rest } from 'msw'"?

I am trying to implement the code from the following example: https://testing-library.com/docs/react-testing-library/example-intro/ Specifically, I am looking at the "Step-By-Step" section for the "Imports" where it shows: // import dependencies import R ...

What could be causing Tailwind CSS to not function properly in my React application?

I followed the installation guide on the Tailwind CSS website, but I'm having trouble getting it to work properly. I attempted to install it in both a React and Vite-React project. Here is the Vite configuration: import { defineConfig } from 'vi ...

When attempting to declare a functional component in React utilizing styled-components in TypeScript, an error is encountered stating "No overload matches this call."

Playground https://codesandbox.io/s/typescript-type-checking-question-0b42t Sample Code type BadgeTypes = { success: string; secondary: string; alert: string; text: string; }; type Theme = { fonts?: object; borderRadius: string; primary?: o ...

Error: Unable to execute this.state.imgData.map due to data type mismatch

Here is my data file for images: imageData = [ { id: 1, imgName: "Banana", imgFile: "banana.jpg", imgQuestion: "What fruit is shown here?", imgAnswer: "This is a Banana" }, ...

Learn how to dynamically change a class name with JavaScript to alter the color of a navbar icon

I have little experience with javascript, but I want to make a change to my navbar icon. Currently, my navbar has a black background with a white navbar icon. As I scroll the page, the navbar background changes to white and the font color changes to black. ...

Is there a way to determine if a user has the ability to navigate forward in Next.js?

I am faced with a challenge of determining whether a user can navigate forward on a webpage. My goal is to have two buttons - one to go back and another to go forward, with the forward button disabled when navigation is not possible. For the back button f ...

object passed as value to competent parent

I'm facing an issue where I am trying to pass a value to the parent component, but it is returning an object instead of the expected value. Here's what I have: Child Component render() { return ( this.props.data.map((val, idx) => { ...

Issue with Material UI: Warning - The <td> element should not be placed inside a <div> element

In my project, I am utilizing React, typescript, and Material UI. One of the components I have created is a standard "Create user form" with basic input fields for username, name, email, etc. I have also included buttons for "Edit" and "Delete." While ever ...

Using an arrow in the Popper component of Material-UI is demonstrated in this example

I noticed on the Popper component page of material-ui, there is an example with a playground. They add an arrow using arrowRef. Can someone clarify where this arrowRef is obtained from? ...

What is the best way to integrate ContextualMenu with Persona in Office Fabric UI React?

Currently, I am utilizing Office Fabric UI React to work on a project. My goal is to implement a ContextualMenu in conjunction with the Persona object. In this particular example, I am demonstrating how ContextualMenu can be applied directly to differ ...

Display only the highest image in the picture carousel using Jquery

My goal is to create a simple image slider using HTML, CSS, and Jquery. However, when I try to move it left by 750px, only the topmost image moves and the rest of the images are not displayed. It seems like all the images are moving at once instead of jus ...

Detecting if a form is in a dirty state before navigating away from a page/route using React Router v6

Here are the versions of the packages I am currently using: React version - 16.13.1 react-router-dom version - 6.0.0-beta.0 react-redux version 7.2.0 Material UI version 4.11.0 I'm looking for the best way to check if a form is dirty (has been change ...

Step-by-step guide on how to include the "content-based-recommender" package in a Reactjs project

I recently started learning React.js and I'm interested in using the "Content-Based Recommender" package from npm. However, after downloading it, I encountered an issue with importing it. The documentation suggests the following: const ContentBasedRec ...

Grid vs Container: Deciding Between the Two - Material-UI

Here's a question I've been pondering lately: Box and Grid are both layout components designed for adding other components inside them. However, I often find that sometimes Box works best for me, while other times it's Grid. And occasionall ...