`Why are my overflow-x and flex-wrap not functioning as expected in React JS?`

Having trouble aligning all the movie posters in a single line? It appears that your overflow-x and flex-wrap properties aren't functioning as expected in your App.css. Here's a snippet of your App.css:

body {
    background: #141414;
    color: #ffffff;
}

.movie-app .row {
    overflow-x: auto;
    flex-wrap: nowrap;
    /* Prevents wrapping on the next line */
}

Here's a glimpse at your App.js:

import React, { useState } from 'react';
import "bootstrap/dist/css/bootstrap.min.css";
import "./App.css";
import MovieList from "./components/MovieList";

function App() {
    const [movies, setMovies] = useState([{
            "Title": "Star Wars: Episode IV - A New Hope",
            "Year": "1977",
            "imdbID": "tt0076759",
            "Type": "movie",
            "Poster": "https://m.media-amazon.com/images/M/MV5BNzVlY2MwMjktM2E4OS00Y2Y3LWE3ZjctYzhkZGM3YzA1ZWM2XkEyXkFqcGdeQXVyNzkwMjQ5NzM@._V1_SX300.jpg"
        },
        // Remaining movie objects...
    ])
    return (
        <div className="container-fluid movie-app">
            <div className="row">
                <MovieList movies={movies} />
            </div>
        </div>
    )
}

export default App;

Lastly, don't forget about your MovieList.js file:

import React from 'react';

const MovieList = (props) => {
    return (
       <div>
            { 
                props.movies.map((movie, index) => 
                    <div>
                        <img src={movie.Poster} alt="movie" /> 
                    </div>
                ) 
            }
        </div>
    )
}

export default MovieList;

Answer №1

This is my styles.css:

body {
    background: #141414;
    color: #ffffff;
}

.movie-app>.row {
    overflow-x: auto;
    flex-wrap: nowrap;
    /*prevent the wrapping on the next line*/
}

This is my App.js:

import React, { useState } from 'react';
import "bootstrap/dist/css/bootstrap.min.css"
import "./styles.css"
import MovieList from "./components/MovieList"

function App() {
    const [movies, setMovies] = useState([{
            "Title": "Star Wars: Episode IV - A New Hope",
            "Year": "1977",
            "imdbID": "tt0076759",
            "Type": "movie",
            "Poster": "https://m.media-amazon.com/images/M/MV5BNzVlY2MwMjktM2E4OS00Y2Y3LWE3ZjctYzhkZGM3YzA1ZWM2XkEyXkFqcGdeQXVyNzkwMjQ5NzM@._V1_SX300.jpg"
        },
        ...
        ])
    return ( < div className = "container-fluid movie-app" >
        <
        div className = "row" > <
        MovieList movies = { movies }
        />< /div >


        <
        /div>
    )
}

export default App;

This is my MovieList.js:

import React from 'react'


const MovieList = (props) => {
        return ( < div > {
                props.movies.map((movie, index) => < div >
                    <
                    img src = { movie.Poster }
                    alt = "movie" / > < /
                    div >
                )
            } < /div>)
        }


        export default MovieList;

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

choose a CSS class within a div element's class name

Hey there, I'm dealing with two HTML divs that both have the same price class of "uvp uvp-price". <div class="product-detail-price-container"> <meta itemprop="price" content="119.8"> ...

I'm having trouble with the DaisyUi navbar; it's not opening the dropdown menu as smoothly as it does on the DaisyUi website when using

Currently, I am experimenting with daisy and tailwind in my project without making many changes to the JavaScript. However, I am facing an issue where it does not behave the same as on the daisyUI website. When I click on 'Parent' in my script, t ...

Adjust the height of a division dynamically

I have the following HTML snippet: <div id="container"> <div id="feedbackBox"></div> </div> The #feedbackBox div is initially not visible. To center the div, the CSS code is used: #container { position: absolute; widt ...

Accelerate blinking timer by utilizing CSS3 animations

I'm currently developing a quiz application that includes a timer counting down from 10 seconds to 0 seconds. As the timer reaches closer to 0 seconds, I am looking to implement a feature where my text blinks faster and faster. Additionally, I would l ...

Guide to inserting an HTML file into an article's content

After downloading an extension from freefrontedit and uploading it to my server in the directory /accordeon, I successfully accessed it by pointing my browser to . However, I am now faced with the challenge of loading the index.html into my Joomla article ...

Is it possible for the Chrome mobile camera to take up the full screen size on

Currently, I am using the code below to access the camera and display the stream. The width of the element is 100%, but the height seems to be around 70%. Is there a better way to make it fill the entire screen? HTML <video autoplay class="screen"> ...

Tips for perfectly aligning heading both horizontally and vertically

https://i.sstatic.net/8ttSh.png https://i.sstatic.net/vSsH5.png My website has a header with text that I want to center both horizontally and vertically. I am currently using the 'text-center' class in Bootstrap 4, which centers the text but onl ...

React Native animation encountered a rendering issue: Invalid transform scaleDisliked value: { "scaleDisliked": 1 }

While working on my react native app, I encountered an issue when trying to apply a transform:scale effect to an Animated.View component. I am using interpolate for this purpose, but unfortunately, I keep receiving the following error message: Render error ...

What is the best way to properly configure axios testing in a React application?

Struggling with testing axios in React - any help? This is my current test.js file attempt: jest.mock('axios'); describe('RssFeed', () => { let component; let data; beforeEach( () => { data = data { data: {...} ...

Text aligned vertically within an element using the table-cell display attribute in the Chrome browser

Struggling to align text inside an element styled with display: table-cell? The issue arises when dealing with multiline text in a tab format. Achieving the correct vertical-align: middle; requires displaying it as a table-cell, which works well in most ca ...

Modifying Table Cell Background Color in ReactJS: A Guide to Conditionally Updating Cell Color Without Affecting the Entire Row

I am working on changing the background color of a cell based on its value. Currently, I am utilizing the following library: react-data-table-component Procedure: If the value is above 0, then the cell's background color will be red. Otherwise, th ...

Is there a way to efficiently display more than 10 data items at a time using the FlatList component in react-native?

Here is the data I am working with: singlePost?.Comments = [ 0: {id: 82, content: "Parent1", responseTo: null} 1: {id: 83, content: "Child1", responseTo: 82} 2: {id: 84, content: "Parent2", response ...

Is there a way to modify or update the CSS classes and overall styling in .gsp files within the Grails framework?

What is the best way to dynamically update a DOM element's class and styling in response to specific conditions or events occurring in a .gsp file? ...

What do you think about removing the Bootstrap styling from the design?

As a newcomer to Bootstrap and currently working on my second project using this framework, I find myself struggling with overriding CSS styles. It can be time-consuming to locate the specific style that needs to be changed rather than starting from scratc ...

Receiving an error of "Object is not a function" when trying to pass an array into a

My React application includes an array of ski days, each with information about different ski trips: allSkiDays:[ { resort: "Squaw Valley", date: new Date("12/24/2018"), powder: true, backcountry: false }, ...

Issue with anchor tag not functioning properly within toggle div

Can you please help me troubleshoot why the anchor tag is not functioning properly within my div elements? When I click on the first div, the second div is displayed but the anchor tag inside the first div does not seem to be working. <script> $(&ap ...

What is the purpose of using a tag within a Next.js Link component?

Exploring the wonders of NextJs, I can't help but question why the a tag is necessary when creating a link. In the tutorial provided, we see this example: <Link href="/"><a>Back to home</a></Link> However, the link s ...

Struggling with aligning images in the center of a square container

Currently revamping my photography website and working on a simple slider to showcase some of my photos. Struggling with aligning the images in divs with padding all around while keeping them centered. I want to replicate the look of my photos on Instagram ...

Error: Invariant violation - App component did not return anything in the render method

I am facing an issue while attempting to render a component based on the promise returned from AsyncStorage. The error message I receive is: Error: Invariant Violation: App(...): No content was returned from the render method. This typically indicates ...

Elements with absolute positioning are preventing drag events from executing

Struggling to create a slider and encountering an issue. The problem lies in absolute items blocking slider drag events. I need a solution that allows dragging the underlying image through absolute positioned items. Any ideas on how to achieve this? MANY T ...