Scrollable Tailwind components

I am working on creating a page layout similar to this design: here is what I want to achieve

The goal is to have a simple homepage with a navbar and split screen. The challenge is to prevent the entire page from scrolling normally and enable independent scrolling for two separate sections. On the left side, there is a list of components that can be scrolled. However, on the right side, there is a single component that should scroll internally. Currently, this is how it looks with my code implementation: view current state here

Below are snippets of both my tailwind and react code.

App.tsx

function App() {
    return (
        <div className='App'>
            <Navbar/>
            <HomePage/>
        </div>
    );
}

Home.tsx

function HomePage() {
    return (
        <div className='flex bg-primary-grey h-screen'>
            <div className='w-1/2 h-full max-h-screen p-5 overflow-y-auto scrollbar-thin scrollbar-thumb-primary-blue'>
                <ul>
                    {
                        items.map((item) => {
                            return (
                                <Item item={item}/>
                            )
                        })
                    }
                </ul>
            </div>
            <div className='p-5 w-1/2 max-h-screen'>
                <RightComponent/>
            </div>

        </div>
    );
}

RightComponent.tsx

    function RightComponent() {
    
        return (
            <div className='bg-white rounded-md p-5 shadow overflow-y-auto'>
          
            <div className='rounded-md shadow text-center p-5 mt-10'>
                <p className='text-lg font-bold text-left mb-3'>Items</p>
                <ul className='flex mt-1'>
                    {
                        exampleItems.map((name) => {
                            return (
                                <ExampleItem name={name}/>
                            )
                        })
                    }
                </ul>
            </div>
            <div className='rounded-md shadow text-center p-5 mt-10'>
                <p className='text-lg font-bold text-left mb-3'>Description</p>
                <p className='text-left'>
                   Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ultricies odio ex, at malesu...
                </p>
            </div>
            </div>
        );
    }

Nav.tsx

function Navbar() {
    return (
        <nav className='bg-primary-grey border-b border-secondary-grey'>
            <div className='max-w-7xl mx-auto px-4'>
                <div className='flex justify-between'>
  <div className='flex'>
                    <div>
                        <a href='#' className='flex items-center py-5 px-2'>
                            <svg xmlns="http://www.w3.org/2000/svg" fill="non...
                                <path stroke-linecap="round" stroke-linejoin="ro...
                            </svg>
                            <span className='font-bold text-3xl text-blue'>App</span>
                        </a>
                    </div>
                </div>

                <div className='flex items-center justify-center'>
                    <form action="">
                        <div className='relative'>
                            <input type="text"
                                   className='bg-white rounded-full py-3 px-4 w-96 bord...
                            
                    </form>
                </div>

                <div className='flex items-center space-x-3'>
                        <a href='#' className='py-2 px-6 border border-solid borde...
                        <a href='#' className='bg-primary-blue py-2 px-6 bo...

The issue is that the <code>RightComponent extends below the page when more content is added. It should remain stacked in the middle of the right section with scrollable content inside.

Answer №1

To achieve this layout, you can utilize the grid property and specify rows as 50px and 1fr. Alternatively, you can set a fixed height for the nav element, such as 50px.

function Navbar() {
    return (
        <nav className='bg-primary-grey border-b border-secondary-grey h-[50px]'>
          ...
        </nav>
    )
}

Afterwards,

function HomePage() {
    return (
        <div className='flex bg-primary-grey h-[calc(100vh_-_50px)]'>
            ...
        </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 could be causing my PHP code to not execute properly alongside the HTML?

I am currently sharpening my skills in PHP by working on a simple web form project. To put it simply, I need to develop a basic web form that accepts a two-dimensional array of European cities along with the distance in kilometers between each pair of citi ...

Animate your menu on hover with jQuery!

I am experiencing an issue with centering the background image below a link. When using mouseleave, the image does not return exactly to the center of the list. Any assistance on how to resolve this would be greatly appreciated. Thank you! Here is the ref ...

Overcoming Troublesome Login Input Box in Web

In an effort to streamline tasks in our office, I am working on automating certain processes. Specifically, this program is designed to log into our insurance company's website and extract information for payroll purposes. Below is the code snippet th ...

The click event fails to trigger while trying to parse external HTML

Currently, I am working on a project that requires me to load HTML from an external file and insert it into an existing div element. Although the process is successful overall, I have encountered an issue where the .click() events do not trigger when click ...

Is it possible for a mobile web application to continue running even when the screen is

Thinking about creating a mobile web application with the use of jQuery Mobile for tracking truck deliveries. I'm interested in sending GPS coordinates back to the server periodically. Is this possible even when the screen is turned off? If not, any ...

exploring for a keyword on the primary Amazon platform (analyzing)

Hey everyone, I noticed that Amazon's main search bar code looks like this: <input type="submit" class="nav-input" value="Go" tabindex="7"> I'm considering creating a function that will locate this tag on amazon.co.uk and perform a search ...

Adaptable bootstrap placement

I have created a form that includes a custom checkbox element. The issue is that the label for the checkbox is not vertically aligned with the checkbox itself. How can I adjust the label to be vertically centered with the checkbox? You can see the code ...

Create a custom div class specifically designed for an image button

Apologies if my title is a bit misleading, I struggled to find the right phrasing. Currently, I have images linked to various social networks using href. For instance, clicking on the facebook icon directs to my Facebook page. The layout looks like this: ...

The masonry reorganization is behaving strangely

I've recently started using masonry for the first time and you can check it out here: Although I have managed to set it up, I am facing some issues with its positioning of boxes when dragging items in. For example, instead of placing a medium-sized ...

Generating an HTML table from SQL data using PHP

I'm attempting to create a dynamic HTML table using PHP to populate it with data from a MySQL database. I've tried using a while loop, but the issue is that it ends up displaying the same first row multiple times. <div class = "container"> ...

What could be causing the hover effect to not work on other elements within the div?

I am working on creating a card that displays only the image when not hovered, but expands and reveals additional information in a div to the right of the image when hovered. Unfortunately, when I hover over the image and then move towards the adjacent div ...

Django works perfectly on local host, but unfortunately, hosting servers are not cooperating

Programming is a new skill for me and I recently created a weather app using Django. The app functions perfectly when I run it locally with the server, but I've encountered difficulties when trying to host it on various platforms. Here is the link to ...

Tips on hovering over information retrieved from JSON data

Within my code, I am extracting information from a JSON file and placing it inside a div: document.getElementById('display_area').innerHTML += "<p>" + jsonData[obj]["name"] + "</p>"; I would like the abi ...

What is the effect of SEO on the use of image width and height attributes for a responsive website

Is it true that setting inline width and height for all images is beneficial for SEO and can improve site loading speed? Here's an example: <img src="http://www.example.com/images/free-size.jpg" width="200" height="400" alt="random image" /> E ...

The appearance of responsive CSS is altered when deployed compared to when it is viewed on the

I'm a beginner in web development and facing an issue with my mobile CSS. The strange thing is that when I view it on localhost, everything looks great, but once deployed (tried both Heroku and GitHub), it appears distorted. Even when I make extreme c ...

Utilizing CSS or JavaScript to define the input type

I currently have a group of checkboxes displayed on a webpage within a DIV labeled OPTIONS, shown below: <div id="options"> <input type="checkbox"..... > <input type="checkbox"..... > <input type="checkbox"..... > <input t ...

Prevent lengthy headers from disrupting the flow of the list items

I've encountered an issue while working on a website that features a list of items. When the title, such as "roller blinds," spans across two lines, it disrupts the layout below. How can I prevent this from happening without compromising on having lon ...

What's the best way to use a single tag with a class to replace multiple nested blockquote tags

I have a collection of messy HTML files filled with repeated blockquote tags used to showcase lines of poetry. For example: <blockquote><blockquote>roses are red</blockquote></blockquote><br> <blockquote><b ...

Is it possible to establish the page state upon loading (in the context of a GET request

At present, my navigation bar is set up to utilize AJAX for loading new pages and window.pushState() in order to update the URL when the AJAX call is successful. I've come to realize that it's crucial to push the page state during GET requests s ...

No space left around the image's border

Whenever I apply a border to an image, it comes with a margin and the image itself receives white padding. How can I remove the margin from the border? This is how I currently have it: border: 1px solid gray; ...