What is the best way to utilize overflow with TailwindCSS?

1. The Home Component:

import React from "react";
import Title from "./Title";
import TaskInput from "./TaskInput";
import TaskList from "./TaskList";

function Home() {
  return (
    <div className="h-screen w-screen bg-primaryGrey flex flex-col justify-center items-center mobile:px-3 mobile:py-3">
      <Title />
      <TaskInput />
      <TaskList />
    </div>
  );
}
export default Home;

2. The TaskList Component:

import React from "react";
import Task from "./Task";

function TaskList() {
  return (
    <div className="bg-green mobile:w-[75vw] mobile:h-[50vh] mobile:pt-3 flex flex-col items-center justify-start mobile:gap-1 overflow-auto">
      <Task />
      <Task />
      <Task />
      <Task />
      <Task />
    </div>
  );
}

export default TaskList;

3. The Task Component:

import React from "react";

function Task() {
  return (
    <div className="bg-secondGrey h-[10vh] w-[70vw] mobile:rounded-[4px] drop-shadow-md mobile:px-2 py-1 flex">
      <div className="h-full w-[10vw] bg-black"></div>
      <div className="h-full w-[50vw] bg-green"></div>
      <div className="h-full w-[10vw] bg-black"></div>
    </div>
  );
}
export default Task;

Why is the scroll not working in the task list? Tasks are shrinked based on the height of TaskList. How can this be resolved?

I tried asking on chatGpt but did not receive a solution.

Answer №1

To optimize the layout, consider adding flex-shrink: 0 to the main <div> within the <Task> component using the shrink-0 class. This will explicitly set the flex-shrink value to 0, preventing elements from shrinking along the main flex axis.

tailwind.config = {
  theme: {
    screens: {
      mobile: '640px',
    },
    extend: {
      colors: {
        primaryGrey: tailwind.colors.slate[500],
        secondGrey: tailwind.colors.neutral[500],
        green: tailwind.colors.green[500],
      },
    },
  },    
};

const Title = () => 'Title';
const TaskInput = () => 'TaskInput';

function Task() {
  return (
    <div className="bg-secondGrey h-[10vh] w-[70vw] mobile:rounded-[4px] drop-shadow-md mobile:px-2 py-1 flex shrink-0">
      <div className="h-full w-[10vw] bg-black"></div>
      <div className="h-full w-[50vw] bg-green"></div>
      <div className="h-full w-[10vw] bg-black"></div>
    </div>
  );
}

function TaskList() {
  return (
    <div className="bg-green mobile:w-[75vw] mobile:h-[50vh] mobile:pt-3 flex flex-col items-center justify-start mobile:gap-1 overflow-auto">
      <Task />
      <Task />
      <Task />
      <Task />
      <Task />
    </div>
  );
}

function Home() {
  return (
    <div className="h-screen w-screen bg-primaryGrey flex flex-col justify-center items-center mobile:px-3 mobile:py-3">
      <Title />
      <TaskInput />
      <TaskList />
    </div>
  );
}

ReactDOM.createRoot(document.getElementById('app')).render(<Home/>);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js" integrity="sha512-8Q6Y9XnTbOE+JNvjBQwJ2H8S+UV4uA6hiRykhdtIyDYZ2TprdNmWOUaKdGzOhyr4dCyk287OejbPvwl7lrfqrQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js" integrity="sha512-MOCpqoRoisCTwJ8vQQiciZv0qcpROCidek3GTFS6KTk2+y7munJIlKCVkFCYY+p3ErYFXCjmFjnfTTRSC1OHWQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.tailwindcss.com/3.4.0"></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

What causes the Ref object to prompt a rerender in this code?

Check out the amazing react-native animation demo on https://reactnative.dev/docs/animated const fadeInOut = useRef(new Animated.Value(0)).current // Initial opacity value: 0 React.useEffect(() => { Animated.timing( fadeInOut, { ...

alignment not behaving as anticipated

My goal is to position two elements on different sides within a container. Although in my coding scenario, these elements are meant to be on opposite ends of a div, for the sake of explanation, let's consider them being on opposite sides of the browse ...

What is the best way to add JSX to the DOM using React?

Looking to make an addition to my DOM. let parent = document.getElementById("TabContainer"); let settings = <Box id="test"> <GlobalSettings activeTab={"test"}></GlobalSettings> </Box> ...

Position an anchor image at the top left corner, no matter the DTD or browser

Is there a way to keep an image with an href fixed in the top left corner of a webpage without affecting any other content and ensuring it functions consistently across different browsers and DTDs? I am facing the challenge of needing to provide a code bl ...

How can an AngularJs developer effectively transition to learning ReactJS from Facebook?

As an experienced AngularJS developer, I am now looking to delve into the world of ReactJS from the ground up. I'm seeking guidance on what my learning curve should look like as I dive into ReactJS. Any help would be greatly appreciated! I'm ...

Issue with React-select multi not functioning as outlined in the provided instructions

I recently implemented a searchable dropdown menu using react-select. Everything was working perfectly until I encountered an issue after selecting an option. An error message saying Each child in an array or iterator should have a unique "key" prop. appea ...

Strategies for detecting changes in object properties and effectively managing updates to mapped objects

I am still trying to grasp the workings of react. It seems like I need to handle the detection of form field changes (similar to how angular and knockout use observables). Here is a snippet from my react code: constructor(props) { super(props); ...

Have you ever wondered how material-ui/Table automatically wraps text in one column? By default, it uses ellipsis to achieve this

The ellipsis is currently being used by default, but I would like it to wrap automatically. Thank you! https://i.stack.imgur.com/bRFtx.png https://i.stack.imgur.com/oaQtp.jpg This is my first time using the material-ui framework and after checking some e ...

How to redirect in Next.js from uppercase to lowercase url

I'm trying to redirect visitors from /Contact to /contact. However, following the instructions in the documentation results in an endless loop of redirects. This is my attempted solution: // next.config.js async redirects() { return [ { ...

Dealing with Excessive Requests in a NextJS Application Routing Layout

Currently, I am developing a NextJS application with an app router that will feature a navigation component. Within this navigation, it is essential to display user information such as a username and avatar. I attempted to implement a layout file based on ...

A flex container containing two divs each with a white-space:nowrap element set at 50% width

How can I create a parent div that contains two child divs, each with a width of 50% that adjusts based on content? The issue arises when one of the child divs has an h3 element with white-space:nowrap;, causing it to exceed the 50% width. I attempted to ...

Is it possible to use PHP to add a prefix to every selector in a snippet of CSS code?

Suppose I have a variable named $css that holds some CSS code. My goal is to prepend a specific text to each selector. For instance, consider the following CSS code: #hello, .class{width:1px;height:1px;background-color:#AAA;} div{font-size:1px} input, a, ...

"The material-ui card in React is showing an error regarding an unexpected prop called 'openIcon'

After attempting to utilize the openIcon property on a CardHeader within the material-ui library, I am encountering a warning message: "Warning: Unknown prop `openIcon` on <div> tag. Remove this prop from the element. For details, see [link to react ...

Launching a new tab with a specific URL using React

I'm attempting to create a function that opens a new tab with the URL stored in item.url. The issue is, the item.url property is provided by the client, not by me. Therefore, I can't guarantee whether it begins with https:// or http://. For insta ...

Guide on applying CSS to option tag within a select element in VUE.js

I am attempting to design a dropdown menu that resembles the one shown in the image. However, I'm currently unable to include any CSS styling. Can anyone provide guidance on how to create a customizable select dropdown in Vue? https://i.stack.imgur.c ...

How can I ensure that Chakra UI MenuList items are always visible on the screen?

Currently, I am utilizing Chakra UI to design a menu and here is what I have so far: <Menu> <MenuButton>hover over this</MenuButton> <MenuList> <Flex>To show/hide this</Flex> </MenuList> </ ...

Tips for rendering the title based on the specific ID provided by the API in nextJS

There is an issue I am facing. I only want to show the "title" based on the ID, but currently all the "titles" are showing up at once. You can see it in the image below: https://i.stack.imgur.com/89D6L.png Here's my code: const getData = () => { ...

Influence of External Style Sheet not reflected in HTML

Just as the title suggests, I have an external style sheet connected to my HTML document, and it appears that the footer element may be incorporating the changes, but none of the other content is. Being new to this, I'm trying to pinpoint where I went ...

Is there a restriction on the number of stylesheets per page in Internet Explorer 8?

Discussing the limitations of CSS in a forum thread, a user shared insights: A user mentioned that Internet Explorer has is known to have a restriction of 4096 CSS rules per file. For more information, check out this source. Additionally, there might be ...

The parent's height dynamically adjusts based on the height of its visible children using only CSS

I am dealing with the following structure: <div class="body"> <div class="wrapper"> <div class="dialog"> <div class="content-0"></div> <div class="content-1&quo ...