Trouble with CSS: Struggling to apply margins to a line of images in React JS

I've encountered an issue where I can't seem to add margin to the row of images. The margin appears fine without any CSS when viewed on a wide screen, but once I scale it down to mobile view, the margin disappears completely. Even after attempting to add a 10px margin via CSS, there is no change in the layout.

As someone who isn't proficient in CSS, I could really use some guidance.

CSS :

.row__posters {
    display: flex;
    overflow-x: scroll;
    overflow-y: hidden;
}
.row__poster  {
    transition: transform 300ms;
    /* preserves the aspect ratio */
    object-fit: contain;
    width: 100%;
    max-height: 100px;
    margin-right: 10px;
}
.row__poster:hover  {
    transform: scale(1.1);
    z-index: 1;
}

React JSX :

import '../styles/Row.css';

const Row = ({ title, movies }) => {
    const posterUrl = "https://image.tmdb.org/t/p/w500/";
    const renderedRow = movies.map(movie => {
        return (
            <img
                className="row__poster"
                src={`${posterUrl}${movie.poster_path}`}
                alt={movie.title}
                key={movie.id} />
        );
    });
    return (
        <div className="row">
            <h1>{title}</h1>
            <div className="row__posters">
                {renderedRow}
            </div>
        </div>
    );
};

export default Row;

This is how it looks on narrow width :

https://i.sstatic.net/OhzC9.png

NOTE: Using NextJS in React.

Answer №1

Have you considered trying to utilize padding as an alternative to using margin? This suggested solution might be beneficial for you:

Apply the use of padding on the .img_wrapper

    .row__posters {
        display: flex;
        overflow-x: scroll;
        overflow-y: hidden;
    }
    .row__poster  {
        transition: transform 300ms;
        /* preserves the aspect ratio */
        object-fit: contain;
        width: 100%;
        max-height: 100px;
        // margin-right: 10px; comment this
        display: inline-block;
        padding-right: 10px;
    }
    .row__poster:hover  {
        transform: scale(1.1);
        z-index: 1;
    }

You can view a live demo here. Hopefully, this solution will suit your needs.

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

Utilizing Flexbox for Creating Horizontally Aligned Boxes with CSS

My goal is to arrange the explanation and participation sections as flexboxes, positioned side by side. Below them, I want the benefits and requirements sections stacked on top of each other. I have attempted to use flex-direction:row; for the explanation ...

Implementing Modals within CellRenderers in ReactJS - Tutorial

cellRenderer: (params) => { var eDiv = document.createElement('div'); eDiv.innerHTML = '<b><div style="overflow:unset"><div class="btn-group btn-group-sm"><button type="button" class="btn btn-primary btn-sm dro ...

Executing a jQuery event after a div's background-image has finished rendering

Greetings and thank you for sparing a moment. I'm curious to know if there exists a method through jQuery to execute a function immediately after a background image in a div has completed downloading and rendering. Imagine you have the following div ...

`Is it possible to output a nested array nested within a value (object element) in React.js?`

I am attempting to display a nested array (sublist) within the object element (value) from the state.list. Despite my efforts, I did not achieve the desired outcome. I have created two components called Orderlist and Item which handle the nested array and ...

The type '{}' does not include a property named 'clear'

I am currently working on integrating the following URL code into my Ionic React app to enable users to sign on a canvas. https://codesandbox.io/s/react-signature-canvas-example-xevhz?file=/src/App.js error TypeScript error in D:/wamp/www/demos/ionicte ...

Issue with getStaticProps in Next.js component not functioning as expected

I have a component that I imported and used on a page, but I'm encountering the error - TypeError: Cannot read property 'labels' of undefined. The issue seems to be with how I pass the data and options to ChartCard because they are underline ...

Maximizing Bootstrap card size in Angular4: A step-by-step guide

How can I make Bootstrap cards resizable on top of other elements when clicked on an icon to make it full screen and overlay on other cards? detail.component.html <div class="card card-outline-info" > <div class="card-header bg-info"><h5 ...

Exploring the process of mapping nested JSON object keys within a React environment

My JSON data structure includes nested objects with the key "alanlar". The number of nested "alanlar" objects is indefinite. The structure looks like this: For example, the "kimlikKarti" object contains "alanlar". Path -> (kimlikKarti.musteriSoyadi , ...

an issue encountered while trying to print a webpage styled with CSS

Users are given the option to print the current page on the website by clicking on a menu element: <li> <a href="#" onClick="window.print()"> <i class="icon-print"></i> Print Page </a> </li> The page contai ...

Ways to update a component when the state changes

When attempting to access components that require authentication, I want to redirect to the login page if the user is not logged in. However, I am facing an issue with initializing the firebase auth object, as there is a small delay. The documentation sugg ...

Tips for positioning a div element at the center in ASP.NET

I have written the following code snippet: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Main" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transit ...

React-Admin error: Attempting to invoke a built-in Promise constructor without using the new keyword is not allowed

I'm currently facing an issue where I am trying to retrieve data using a hook. Strangely, there are no TypeScript errors appearing, but when I run the code, a console error pops up stating "Uncaught TypeError: calling a builtin Promise constructor wit ...

Activate the button to effortlessly load pages with a visually engaging animation

I have been facing a problem for the past couple of days. I need help with achieving a specific functionality on my website. When button1 is clicked, I want to load the page in a div class named "loadpage" with an animation coming from the left. Similarl ...

Styling CSS according to the specific words found within the content

After retrieving text data from an API, I want to enclose a specific word, for example "Biography", with <span> and </span> tags in order to apply unique styling. Can anyone provide guidance on how to accomplish this using jQuery or JavaScrip ...

Employing debounce in conjunction with React hooks leads to an infinite number of requests

Seeking a solution to efficiently fetch data from the server based on changes in the search input without triggering a new request for every character entered? Utilizing debounce from the use-debounce package found at https://github.com/xnimorz/use-debounc ...

Unable to combine mui theme with emotion css prop

I recently made the switch from overwriting styles in my styles.css file with !important to using emotion css prop for implementing a dark theme in my web app. Below is the code snippet from App.tsx where I define my theme and utilize ThemeProvider: const ...

The React application is experiencing crashes whenever a user tries to access a page that hasn't had its actions

I'm diving into my first app development journey using REACT, HOOKS, REDUX, AND REACT ROUTER. The initial stage has been smooth sailing, with the app functioning flawlessly on the home page - a static welcome page devoid of any React state. However, n ...

Issue: Invariant violation occurred when attempting to retrieve a frame for an index that is out of range (NaN) in react-native-ios while using the

enter image description hereAttempting to showcase a blog content in react-native utilizing the fetch-api. I am finding myself lost in the syntax, as it is getting more complicated with the examples I find online. The API was generated locally from PHP-PDO ...

Prevent unexpected page breaks in <tr> elements on Firefox (Could JavaScript be the solution?)

Wondering if there are any ways, possibly through JavaScript or CSS, to avoid having page breaks within <tr> elements specifically in Firefox. Given that FF does not yet fully support page-break-inside, I assume this might need to be addressed using ...

Establish the starting value for the material user interface checkbox

function mapStateToProps(state) { return { model: Selectors.Quotes.getCurrentQuote(state), }; } class Customer extends Component { state = { checkedEnergyConcessionHolder: false }; ...