I'm having trouble getting my flex items to maintain a specific width and height while staying in a single line

I've been out of practice with flexbox for some time and I can't figure out why the width and height properties are not being applied to each flex item as expected. All the items seem to have an equal width, but not the width that I specified. Additionally, they are all displayed on a single line even though I didn't set it to nowrap.

    const Filter = () => {
    return (      
      <div className="store-results-inner-container">
        {alphabetIntoArray.map((c, i) => {
          return (
            <div key={i} className="alphabet-individual-container">
              {filteredValues
                .filter(store => store.title.rendered.startsWith(c)).length === 0 
                ? <h1 ref={ el => itemsRef.current[i] = el } className={'Grey'}>{c}</h1>
                : <h1 ref={ el => itemsRef.current[i] = el } className={'notGrey'}>{c}</h1>   
              }         
              {filteredValues
                .filter(store => store.title.rendered.startsWith(c))
                .map((item, index) => (   
                  <li key={index}>{item.title.rendered}</li>
                ))}
              </div>
          );
        })}
      </div>
    );
  }

css:

    .store-results-inner-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top:5%;
    padding-bottom:5%;
    height: auto;
    width: 90%;
    padding-left: 5%;
    padding-right: 5%;
    background-color: seagreen;
}

.alphabet-individual-container {
    width: 1150px;
    height: 200px;
    flex: 1 1 0px;
}

output: https://i.sstatic.net/WiJn0.png

desired output:

My goal is to ensure that each item has equal height and width, with 3 items per column that are responsive.

Answer №1

To ensure that the items in your flex container wrap properly, you need to add flex-wrap:wrap since the default is no-wrap. Additionally, if you want the items to have equal height and width, make sure to specify that as well instead of giving them different dimensions. You might consider setting a width of 30% and a fixed height.

Alternatively, using a grid layout could be a better solution.

I created a quick example for reference: https://codepen.io/JonathanDamiani/pen/abBOgBR

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 meaning of this CSS acronym?

div[id^=picture]:target{ /*applying various styles here*/ } I stumbled upon the snippet of code shown above on a website discussing CSS image galleries. Can anyone clarify what this code accomplishes? Appreciate it. ...

The background color spills outside the column when using 100% width

Bootstrap 5 is being used, and two columns have been created on the page. The current output looks like this: https://i.stack.imgur.com/P6oZs.png Now, there's a need to display an orange color from end to end of the left column. To achieve this, h- ...

What methods can be used to maintain the selected date when the month or year is changed in the react-datepicker component of reactjs?

At the moment, I am using the Month selector and Year selector for Date of Birth in the react-datepicker component within a guest details form. The current functionality is such that the selected date is highlighted on the calendar, which works fine. How ...

What is the best way to organize and position numerous images and text elements within a flex container?

Currently learning the ropes of web development and working on a practice project. My goal is to utilize flexbox in order to achieve a layout similar to this design. Here's what I have so far: .flex-container { display: flex; align-items: cente ...

Tips on incorporating a style-tag into the body of an Angular 5 application

We offer a service that collects a vast amount of data to be displayed in an angular 5 application. The model used for displaying this data is constantly evolving and shared across multiple applications, so I need to import it dynamically. My approach inv ...

Component does not display dynamically created DOM elements

I have a function that creates dynamic DOM elements like this: const arrMarkup = []; const getMarkup = () => { if (true) { arrMarkup.push( <Accordion expanded={expanded === cust.name} onChange={handleChange(cust.name)}> ...

Having issues with ToggleClass and RemoveClass functionalities not functioning properly

As a novice in Jquery and CSS/scss, I've managed to create dynamic bootstrap cards for recording players. Each card consists of a music-container with control-play and vinyl elements. I aim to have multiple bootstrap cards generated based on the data ...

"Exploring the optimal form pattern in NextJS v14: Which approach reigns supreme

I've been tasked with creating a form in nextjs. In plain react, I used to handle the state of each input using useState hook. However, after reading the official nextjs documentation, it seems like the recommended practice is to validate inputs on th ...

How can a div be utilized to create a footer with two columns?

Is there a way to design a two-column footer using only divs and no tables? The dimensions of the footer are set at 980px and it needs to include... Copyright 2010 xyz.com (to be placed on the left side) About us | privacy | terms (to be placed on the r ...

React, Storybook - Error TS2307: Button module not found or its type declarations. Can Storybook resolve this issue?

In my React project, I have a Button component created with "create-react-app" that uses absolute paths for importing. When trying to import { Button, ButtonProps } from 'Button', I encountered an error with TS2307. The absolute path 'Butto ...

The fixed position div remains stationary as the page scrolls

Below, I am attempting to fix the position of the 'inner-navigation' div within the 'compare-display' box by making it absolutely positioned. However, when scrolling, the 'inner-navigation' div is not staying fixed. How can I ...

Executing asynchronous actions with useEffect

Within my useEffect hook, I am making several API requests: useEffect(() => { dispatch(action1()); dispatch(action2()); dispatch(action3()); }, []); I want to implement a 'loading' parameter using async/await functions in the hook ...

The functionality of CKEditor is compromised when used in conjunction with React Material-UI

I've been struggling with integrating Material UI and CKEditor5. The issue I'm facing is that CKEditor doesn't seem to be working properly. Despite trying to apply editor features like bold or italic, nothing changes on the screen. However, ...

The component 'ProtectRoute' cannot be utilized within JSX

While using typescript with nextjs, I encountered an issue as illustrated in the image. When I try to use a component as a JSX element, typescript displays the message: ProtectRoute' cannot be used as a JSX component. import { PropsWithChildren } from ...

Navigating between components in React: How to create links that open a different component on the same page

I need help with a basic app that consists of a login page and a registration page. I want to add links between these pages using React. I would appreciate input from experienced colleagues on the best approach to achieve this. Below is the code for the lo ...

Exploring type definition for function arguments in TypeScript and React

There is a high-order component (HOC) designed to store the value of one state for all input and select elements. The output function accepts arguments ({text: Component, select: Component}). An error is displayed while typing an argument: TS2322: Type &ap ...

Creating React Context Providers with Value props using Typescript

I'd prefer to sidestep the challenge of nesting numerous providers around my app component, leading to a hierarchy of provider components that resembles a sideways mountain. I aim to utilize composition for combining those providers. Typically, my pro ...

The footer is not displaying at the bottom of the page in Firefox

While the footer design is functioning well in both Chrome and IE, it seems to be encountering issues with Firefox. div.footer{ width: 100%; padding: 0px; margin-top: 200px; font-size: 0.6em; line-height: 1.2em; clear: both; po ...

NextJS for Self-hosting Fonts

I'm facing difficulties with self-hosting webfonts in my NextJS application. The browser is trying to access the fonts using this URL: localhost:3000/_next/static/css/fonts/Avenir.woff2 However, the actual path for these fonts is: _project_dir/static ...

A simple guide to viewing a sequential list of loaded stylesheets in Google Chrome

I've been trying to figure out the loading order of CSS stylesheets in Google Chrome, but I'm finding it a bit confusing. Despite my attempts to use Dev Tools -> Network tab -> filter for Stylesheets, I keep getting different results each t ...