What is the best way to configure my card components for a flex display?

Currently, I am in the process of learning React. I have a file named new_card_component.js that is responsible for displaying data fetched from the data.js file. The issue arises in my AirBnB.js file, where I'm passing the AirbnbApp module to a section called data-container, which has a flex property. However, the card components are not being displayed in a flex layout as expected.

import "../CSS/airbnb.css";
import AirbnbApp from "./airbnbApp";

function AirBnBPage(){
    return (
        <div>
            <NavBar/>
            <Hero/>
            <section className="data-container">
                <AirbnbApp/>
            </section>
        </div>
    )
}
export default AirBnBPage

In my new_card_component.js file:

import { FaStar } from "react-icons/fa6";
import "../CSS/airbnb.css";

function NewCard(prop){
    return (
        <div className="card-sub">
            <img src={prop.mainimage} alt="trainer"/>
            <div className="info-group">
                <a href="https://"><FaStar/> {prop.rating} ({prop.review})</a>
                <p>{prop.country}</p>
            </div>  
            <p>{prop.message}</p>
            <div className="info-group">
                <p>Available spots : {prop.spots}   Price : {prop.cost} $</p>
            </div>
        </div>
    )
}

My CSS file - airbnb.css:

.data-container{
    /* background-color: red; */
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    width:1200px;
    margin:0 auto;
    align-items: center;
    justify-content:flex-start;
}
.card-sub{
    margin:25px 0 0;
    width:320px;
    border:2px solid black;
}
.card-sub img{  
    width:220px;
    height: 300px;
    border-radius: 10px;
}
.info-group{
    margin-top:10px;
    display: flex;
    gap:0.7rem;
    margin-left:10px;
}

I attempted to apply the display:flex property to the data-container section, but it did not resolve the issue. The card components are still being displayed on separate rows despite having an array with 4 objects in my data.js file, resulting in each card component being shown on its own row.

Answer №1

It turned out that the issue was actually in the file removed from the question, lucky I checked before proceeding.

In the AirbnbApp.js, make sure to return the cardElements directly instead of wrapping them inside a div. Using display: flex affects direct children, so avoid unnecessary div wrappers.

       }].map(function (cardItem) {
            return <NewCard mainimage={cardItem.coverImage} rating={cardItem.stats.rating} country={cardItem.location} message={cardItem.description} cost={cardItem.price} spots={cardItem.openSpots} review={cardItem.stats.reviewCount} />
        })

    return cardElements;
}

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

Utilize custom {tags} for replacing strings in a CSS file using str_replace in PHP

My code consists of a script that updates a CSS file based on user input from an html form. The script executes a str_replace function, scanning the CSS file for specific "tags". For example: html,body { background: {bgcolor} url(../images/bg.jpg) re ...

What steps can I take to update my data fetching method in order to prevent outdated information from being displayed on the first dynamic route

In my current Next.js project, I am working on an application that allows users to create and manage multiple Kanban boards. Users have two primary ways of accessing their different boards: Users can see a list of boards on the Home page and click on the ...

React js is not displaying the image

Currently, I am working on developing an application using Spring Boot for the backend and React.js for the frontend. Within my database, I have fields for "title," "image," and "content." When fetching data without using the frontend, all details includin ...

"Date validation issue with Formik and Material-UI's Datepicker component: min and max dates not

This particular issue has really been getting to me. I just can't seem to make the min and max date functionality work at all. Below is the snippet of code in question: <DatePickerField name={dob.name} label={dob.l ...

Creating a task management application using AXIOS and VUE for easy data manipulation

I am currently working on a small app to enhance my skills in VUE and Axios. However, I am facing a roadblock when it comes to the update functionality. I am struggling to pass the ID to the form for updating and despite watching numerous tutorial videos ...

Referencing another component in StyledComponents

I'm looking to modify the properties of my parent component's :after selector whenever the child element is focused. It seemed straightforward at first, but for some reason, I just can't seem to make it work. Here's a glimpse of my comp ...

The Material Icons font family must be loaded via Exponent as it is not a default system font

Currently, I am utilizing the Icon component from react-native-vector icons by importing it with this code: import Icon from 'react-native-vector-icons/MaterialIcons'; It appears that the connection is established correctly. The snippet of cod ...

When using angular's ngHide directive on a button, it will still occupy space in the

At the bottom of this HTML file, there are 3 buttons displayed. The first image illustrates the layout of the 3 buttons. The second image demonstrates what happens when the middle button in the footer is commented out. The third image shows the situat ...

Place the span element above the div container

I recently created some social media buttons with share counters, but I'm facing an issue where the counter data appears inside the buttons rather than on top of them. Has anyone encountered this problem before? Is there a way to display the numbe ...

Can Masonry.js content be perfectly centered?

I am currently experimenting with creating a layout consisting of one to four variable columns per page using the Masonry plugin. I have been impressed with how it functions so far. However, there is an aggravating gap that persists despite my best effort ...

Modify the button text when it is hovered over

I am attempting to modify the text displayed on a button when hovering over it in a React component from Ant Design. However, I have not been successful so far. Button <div className={ status == "verified" ? `${styles.btn1} ${styles.btn1C ...

Incorporating fresh data from a node.js backend to refresh a webpage section

I'm currently working on creating an app that can retrieve the song a user is currently listening to using a web scraper. While I've managed to direct users to the page and display the current song title, they must manually refresh the entire pag ...

Display the list items when the page first loads

I currently have this code snippet: <nav> <ul class="sel"> <li> <a href="#LINK1" data-title="A">A</a> </li> <li> <a href ...

Attempting to implement innerHTML functionality into a React todo list

As I strive for new challenges, I am experimenting with the functionality of adding tasks through a click event labeled as "add task". Although seemingly simple, I am still exploring and learning more about react. My approach was to implement a ternary op ...

How can I deploy React applications to AWS EC2 using Github Actions and AWS CodeDeploy?

I am currently facing a challenge in setting up a React app within Github Action workflow and deploying it on an EC2 instance. The issue I'm encountering is the inability to access the /build folder that is created during the action process. Below i ...

Step-by-Step Guide for Installing Next.js with React 17

Is there a way to install Next.js with React 17? I tried using the command npx create-next-app --ts, but it installed Next with React 18 instead. Unfortunately, I can't use React 18 because Stripe is currently not compatible with R18 (https://www.npmj ...

What is the process for customizing the default animation in the Dialog component?

Currently I am utilizing the Material UI framework and looking into modifying the default animation for a Dialog opening. Specifically, I would like the Dialog to appear from bottom to top when it opens up. Any suggestions on how this can be achieved? Ap ...

The information retrieved from an API fails to populate the table on the NextJS platform

I am facing an issue while trying to populate a table using an API call in NextJS. I have used the getStaticProps function to retrieve the data and pass it to the component. However, when I attempted to use the map() function to iterate over the data objec ...

Navigating a Bootstrap carousel with buttons: A step-by-step guide

Here is the code snippet I am currently working with: <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-2.1.4.js"></script> <link href="https://code.jquery.com/ui/1.11.4/them ...

Node Express and React Axios have implemented a CORS policy that restricts access to XMLHttpRequest

Currently, my node server is running on localhost port 5500 and react is on localhost port 3000. I am using Axios to send requests to the node backend. Interestingly, when I set axios.defaults.withCredentials = true, I encounter an error. However, if I swi ...