FlexBox responsive items that are expandable getting cut off

I am currently working on creating a row of expandable items. While I have almost achieved the desired behavior, there are a few issues that I need help with:

  1. On Desktop, the items are cut off and not fully visible.
  2. On Mobile, half of the items are missing and cannot be scrolled to.

Here is how it looks like (imgur)

The problems stem from my Flex setup and how I manage it. I recently grasped the basics but now need to understand the interactions between different properties better. Any explanation alongside a solution would be greatly appreciated!

This is the Card that holds these items (written in kotlin):

  val x = { props ->
             // this is the Card
            return@fc div("w-full flex flex-col items-center shadow-lg p-4 rounded-lg lg:shadow-none") {

                // This is the container holding the items
                div("flex w-full gap-3 overflow-x-auto items-start justify-center my-5 snap-x p-2") {
                    model.content.forEachIndexed { index, item ->
                        ModeratedContentItem {

                        }

                    }

                }
            }
        }

And here are the items:

return@fc div("w-full shadow-md rounded-md " +
            "items-center max-w-sm flex-initial lg:shrink-0 snap-center " + if(expanded) " flex-none " else " shrink ") {
 ...........

The concept is for the items to enlarge on desktop and shrink gradually on smaller screens, then expand again when needed. However, playing around with shrinking and flex seems to mess up the scrolling functionality.

According to my understanding of FlexBox workings, this setup should function correctly. I'm unsure why the scrolling behaves unexpectedly while experimenting with shrinking and flex properties.

EDIT: Adding Justify Content Center to the item container is causing most of the issues.

I aim to have the items start from the center (especially when there are fewer items) and by using items-start, ensure that expanded items do not affect others and remain connected to the top.

EDIT: Codesandbox link provided here, although it doesn't work well on mobile, it showcases the desktop issue accurately.

You can observe that when multiple items are present, the parent container stretches. If you expand one item, the parent container adjusts to the correct size, but the reason behind this behavior remains unclear.

Answer №1

After encountering a frustrating bug, thankfully applying the solution suggested in the article resolved the issue

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

The module cannot be located due to an error: Package path ./dist/style.css is not being exported from the package

I am facing an issue with importing CSS from a public library built with Vite. When I try to import the CSS using: import 'rd-component/dist/style.css'; I encounter an error during the project build process: ERROR in ./src/page/photo/gen/GenPhot ...

The content div in CSS is causing the menu div to be displaced

I have encountered a difficulty in describing the issue at hand as I am still in the learning phase and consider myself a beginner. Within my container div, there are two other divs - one for the menu and another for the content. Both of these divs float ...

Picture appears to be off-center

I created a loginPage.php file with the following content: <?php //some php stuff ?> <!DOCTYPE html> <html> <head> <title>Login Form Design</title> <link rel="stylesheet" type="text/css" href="stylelogin.c ...

Using React to Render a Component with Local Storage Information

I'm in the process of developing a history list component for a form within a react application and encountering difficulties with local storage. The goal is to display a list of previous user inputs from the local storage data. My current approach i ...

Integrate CSS and JavaScript files into Node Express

I am facing an issue including my CSS file and JavaScript file in a node-express application, as I keep getting a 404 not found error. Here is the code snippet that I am using: 1. In server.js var http = require('http'); var app = require(' ...

The onClick event in ReactJs appears to be ineffective when used with a button HTML element

Can someone help me troubleshoot this issue in my ReactJs app? import React from 'react' import '../../../assets/styles/authentication/login.css' import '../../../assets/bootstrap/css/bootstrap.min.css' import { login } fro ...

Is it possible to overlay a div onto a Google Map?

Does anyone know of a plugin or method that can achieve this? I have a website at this link, and at the bottom there is a map. I'm looking to add a small overlay box on top of the map with contact information inside. Edit: The box should be position ...

It appears that the JSX onClick event is being triggered by default

I feel like I'm missing something obvious. I have written some code but it's not behaving as expected. I anticipate the terminal to display a log only when the button/link is clicked, but it appears to be logging regardless. Here is the code sn ...

Exploring the contrast of app.use and app.get *within the realm of proxy servers*

Seeking clarification on the distinction between express's app.get() and app.use(). I am aware that app.use is applicable to all HTTP verbs. According to sources, "app.use() adds middleware instead of a route" I am curious about why this particular ...

Guide to assigning a value to a label in Razor's Html.DropDownList

I'm trying to assign a specific label value to the dropdownlist instead of the default value, but it seems like I might be making a mistake. @Html.DropDownList("cboCategoria", new SelectList(Model, "ID", "Nome"), new { @id = "cboCategoria", @label = ...

Mastering socket emission and disconnection in reactjs

When using the onchange function, I am able to open a socket and emit/fetch data successfully. However, a new socket is opened on any event. I need to find a way to emit data from the same socket ID without opening a new socket each time. Could you pleas ...

The -webkit-background-clip feature seems to be malfunctioning in Safari

I am experiencing an issue where the code works perfectly on Chrome but fails to function properly on Safari. I have been unable to pinpoint the cause of this discrepancy and any assistance or insights would be greatly appreciated. For those interested, a ...

The Markup() function in Flask is used to generate markup content that is not enclosed within

Before I explain my issue, let me go ahead and share the code with you. Using Jinja in HTML <p>{{ item }}</p> 'Flask' item = Markup('<ul><li>list item 1</li><li>list item 2</li></ul>') ...

I've exhausted all my knowledge but still unable to get Tailwind to work

I've been troubleshooting Tailwind for the past 6 hours. Managed to set it up in a simpler Nextjs/React/Typescript project, but struggling to get it working in this larger codebase. I'm sure I'm missing something obvious, but I'm at a ...

Render doesn't wait for the componentWillMount lifecycle method

I'm currently working on implementing a redirection to the home page for logged-in users. I'm using ping to fetch login information, setting a state based on the response, and then checking that state in the render method for redirection. However ...

Show the button only when the text is updated

Is there a way to display a button only when the quantity of items in the cart changes, similar to the eBay shopping cart feature? I was able to implement it but it's not functioning as expected. Here is the link to what I have so far. Does anyone kno ...

Wordpress problem with Bootstrap JavaScript code involving data-toggle="collapse"

Currently facing an issue with my project. This is my first attempt at creating a WordPress blog, inspired by the HTML site www.humantools.com.mx and building a blog for it at www.humantools.com.mx/blog. There's a strange problem: when logged in, the ...

Why did the creators choose to integrate a dropdown menu into Twitter Bootstrap?

While exploring Twitter's Bootstrap framework, I couldn't help but be impressed. However, one feature that has left me a bit puzzled is the dropdown navigation menu. First of all, to view child links, you need to click on the parent. I understan ...

Passing data from getServerSideProps to an external component in Next.js using typescript

In my Index.js page, I am using serverSideProps to fetch consumptions data from a mock JSON file and pass it to a component that utilizes DataGrid to display and allow users to modify the values. export const getServerSideProps: GetServerSideProps = async ...

Exploring the integration of RTK query data within the getStaticProps() function of Next.js (encountering an error)

I recently attempted to integrate RTK query into my Next.js project, but encountered an error when trying to use the fetched data in getStaticProps(): The error message states that the React Hook "useGetEventsQuery" is being called within a function name ...