Cannot overflow a long flex div within parent div in CSS-Tailwind to achieve sliding effect

In the div with a class of scroll-content, I have a long list of images that I want to hide under a scroller div. My goal is to create a slide effect using arrow buttons. However, the flex box expands beyond 100% of the container. This issue arises within a Next JS application.

let products = [{
  name: "sample 1",
  imageUrl: "https://picsum.photos/536/354"
}];

const Home = async () => {
return (
  <main className="flex min-h-screen flex-col items-center w-full">
    
    <div className="px-2">
      {" "}
      <div className="w-full mt-3">
        <span className="text-lg font-bold">Top picks</span>
      </div>
      <div id="scroller" className="w-full overflow-hidden z-10">
        <div id="scroll-content" className="flex z-0">
          <div className="inline-block h-[10rem] w-[10rem] flex-shrink-0">
            <img
              className="h-full max-w-full rounded-lg object-cover shadow-lg"
              alt={products[0].name}
              src={`${products[0].imageUrl}`}
            />
          </div>
          {/* Repeat the above div for other images */}
          <div className="inline-block h-[10rem] w-[10rem] flex-shrink-0">
            <img
              className="h-full max-w-full rounded-lg object-cover shadow-lg"
              alt={products[0].name}
              src={`${products[0].imageUrl}`}
            />
          </div>
          {/* Add more divs as needed */}
          {/* The remaining image divs are omitted for brevity */}
        </div>
      </div>
      <div className="w-full mt-3">
        <span className="text-lg font-bold">Quick Links</span>
      </div>{" "}
    </div>
  </main>
);
};

export default Home;

Despite trying methods like inline-block and grid, achieving the desired functionality has proven to be challenging. Grid causes internal divs to overlap each other, while inline-block wrapping is not satisfactory either.

Answer №1

To rectify the issue of overflowing children causing a wider element than the viewport, you should apply max-width: 100% using the max-w-full class to the div.p-2 element.

let items = [
  {
    title: 'example',
    imageURL: 'https://picsum.photos/536/354',
  },
];

const Homepage = () => {
  return (
    <main className="flex min-h-screen flex-col items-center w-full">
      <div className="px-2 max-w-full">
        {' '}
        <div className="w-full mt-3">
          <span className="text-lg font-bold">Popular picks</span>
        </div>
        <div id="scroller" className="w-full overflow-hidden z-10">
          <div id="scroll-content" className="flex z-0">
            {/* Repeat the following div for additional images */}
            <div className="inline-block h-[10rem] w-[10rem] flex-shrink-0">
              <img
                className="h-full max-w-full rounded-lg object-cover shadow-lg"
                alt={items[0].title}
                src={`${items[0].imageURL}`}
              />
            </div>
            <div className="inline-block h-[10rem] w-[10rem] flex-shrink-0">
              <img
                className="h-full max-w-full rounded-lg object-cover shadow-lg"
                alt={items[0].title}
                src={`${items[0].imageURL}`}
              />
            </div>
            {/* Add more similar divs as required */}
          </div>
        </div>
        <div className="w-full mt-3">
          <span className="text-lg font-bold">Helpful Links</span>
        </div>{' '}
      </div>
    </main>
  );
};

ReactDOM.createRoot(document.getElementById('app')).render(<Homepage />);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.3.1/umd/react.production.min.js" integrity="sha512-QVs8Lo43F9lSuBykadDb0oSXDL/BbZ588urWVCRwSIoewQv/Ewg1f84mK3U790bZ0FfhFa1YSQUmIhG+pIRKeg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.3.1/umd/react-dom.production.min.js" integrity="sha512-6a1107rTlA4gYpgHAqbwLAtxmWipBdJFcq8y5S/aTge3Bp+VAklABm2LO+Kg51vOWR9JMZq1Ovjl5tpluNpTeQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.tailwindcss.com/3.4.5"></script>

<div id="app"></div>

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

When clicking on the material-ui autocomplete feature in a React JS application, a blank page unexpectedly opens

I am encountering a problem where, upon clicking the Autocomplete component imported from material-ui, it displays a blank page. const defaultProps = { options: catalogs, getOptionLabel: (option) => option.catalogsLink, }; <Autocomplet ...

What is the best way to convert my create-react-app project into a standalone HTML file that includes embedded JavaScript?

For a test assignment for a new job, I completed a simple create-react-app project. However, there is a requirement that the project must be submitted as a single HTML file with embedded JS and CSS. How can I convert my create-react-app project into a sin ...

Displaying a JSON object in a component's state through appending

I am currently working with a function that takes the state of an object as input and performs various operations on it. After these operations, I need to update the state accordingly and display it in JSON format. Here is the initial state: state= { ...

Prop type failure: The `actions` prop is specified as mandatory in the `Testing` component, however, its value is currently undefined

I am working on a project that involves creating a login form using React and Redux. Here's a snippet of my app.js: import React from 'react'; import { render } from 'react-dom'; import Input from 'react-toolbox/lib/input&apo ...

Utilize jQuery to retrieve data attributes and set them as CSS properties in a key-value format

Looking at the HTML below: <h4 data-padding-top="100" data-padding-left="0" data-text-align="left" data-color="#ffffff">Promotion Two</h4> I aim to use the data attributes as CSS styles for the H4 element. I have attempted to achieve this ...

Exploring Material UI's Typography fontSize feature

After upgrading my material UI version from 3.9.4 to 4.11.0, I had to make some changes in the theme style override section to fix certain warnings: https://i.sstatic.net/GjzI9.png https://i.sstatic.net/LVHGk.png However, I encountered a challenge with ap ...

Display the item with jQuery once the CSS generated by jQuery has finished loading

Is it possible to delay the visibility of an object until my script finishes loading? I tried using ajaxcomplete() and ajaxSuccess() without success. Check out the code snippet below for an example. There's an image with the id: imagefocus. Whenever ...

What is the process for transferring a function to reducers in Redux Toolkit?

In one of my files called Main.tsx, I have a function that sends a request and retrieves data: async function fetchProducts(productsPage = 1, id?: number) { const itemsPerPage = 5 let url: string if (id) { url = `https://reqres.in/api/ ...

What could be causing the CSS loader in webpack to malfunction?

I am currently working on implementing the toy example mentioned in the css-loader documentation which can be found at https://github.com/webpack-contrib/css-loader Additionally, I have also followed a basic guide that recommends similar steps: https://cs ...

Encountering an issue when trying to use SVG clip-path in Safari

I'm currently experimenting with creating a unique hexagonal border around a button. My approach involves enlarging the container element by a few pixels compared to the button size and using the same clip-mask on both elements to achieve a bordered e ...

Struggling to locate production files with the combination of `fast-glob` and `process.cwd()` when dealing with dynamic route segments

In the directory structure, I have a blog page located at app/[locale]/home/blog/page.tsx. import glob from 'fast-glob' import path from 'path' const BlogPage = async () => { let pages = await glob('**/*.mdx', { cwd: ...

The updated version of Angular from 13 to 16 has implemented a new default value for primary colors

I recently upgraded my angular (+material-ui) system from version 13 to 16, and encountered an issue with the primary color of my custom theme. It seems that the value is no longer being recognized and defaults to blue. After updating the angular version, ...

The animation isn't loading

I discovered a handy script that displays a waiting message when my form is submitted. I implemented jquery-ui to showcase this message in a dialog box, and it was successful. However, upon customizing the text and adding an animated gif background using C ...

A new ASP.NET MVC-5 web application is missing the class definition for "input-validation-error."

I recently created a new ASP.NET MVC-5 web application using Visual Studio 2013. When I attempted to use the built-in login form and left the required fields empty, I noticed that the fields were not highlighted in red as expected. https://i.sstatic.net/m ...

Integrating React js with Layout.cshtml: Mastering the Fusion of React Routing and ASP.NET MVC Routing

My current project involves an ASP.NET MVC core application with the View written in cshtml. The routing follows the conventional asp.net mvc routing pattern. However, I've recently implemented a new module using React JS. Now, I'm faced with the ...

Oops! It seems like React has encountered an error: TypeError - It can't read the property 'split' because it

As a novice, I am trying to decipher a token but keep encountering an error. import Cookies from 'js-cookie' function parseJwt(token) { var base64Url = token.split('.')[1]; var base64 = base64Url.replace(/-/g, '+').replace(/_ ...

Issue: Unable to convert a value of undefined or null to an object | NextAuth

Attempting to create a custom sign-in page with Google using NextAuth and Firebase led to the following code: api/auth/[...nextauth]/route.js ...

Animating the change in width of a column using Bootstrap 4

I currently have two columns structured like this: <div class="container"> <div class="row"> <div class="col-9"></div> <div class="col-3"></div> </div> </div> Through Angular, I am ch ...

What could be causing the error I'm encountering after implementing Auth0 with Next.js?

Following the instructions in this tutorial, I completed all 5 steps and launched the server only to encounter the following error: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) ...

Any tips on how to personalize the loading animation for single pages using CSS and GIFs?

presentLoading(message) { this.loading = this.loadingCtrl.create({ dismissOnPageChange: false, spinner:'hide', content:`<img class="load" src="assets/dual.gif" />`, }); this.loading.present(); } Hello there! I am working with the ...