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

Bootstrap for a more streamlined container

https://i.sstatic.net/fJ8nt.png My Bootstrap setup includes a container-fluid with multiple cards inside. I want to adjust the container layout to stack the cards more closely together in a vertical direction, instead of being displayed in a grid format. ...

Tips for aligning a logo in the center of a navigation bar

I'm struggling to center a logo within the navigation bar of a website I am designing. Despite my attempts, I have not been successful in achieving the desired result. My goal is to have the logo positioned in the middle of the navigation bar, with ot ...

Move the contents of a div to the right side

One of the issues I am facing is with aligning replies to comments correctly in my comment section. The replies are not aligning properly with the parent comment and it's causing a display problem. Link to JSFiddle for reference Here is the CSS code ...

The angular view is lacking a CSS class

index.html: <div ng-view="myview.html"></div> myview.html: <table class="table table-striped table-hover"> <tr> <td>Name</td> <td>Product</td> </tr> <tr ng-repeat="deal in deals" class="clickableR ...

I'm overwhelmed by the concept of linear gradients

I've been struggling to recreate the CSS gradient, so here's what I'm aiming for: https://i.sstatic.net/4gIHV.png Here are the details: Gradient colors: Start color: #1696B6 with 50% opacity End color: Black with 100% transparency https:// ...

How to create a calendar selection input using PHP?

Before I start writing the code myself, I am searching to see if there is already a solution available or if someone has previously outsourced the code. Below is an example of my date selection: I want to create a feature where selecting a month will aut ...

JS animation triumphant

I have developed an app that utilizes a checkbox to control the appearance of an overlay on a screen. To ensure smooth transitions, I have incorporated animations into the process. #overlay{ position:absolute; height: 100vh; width: 100vw; ...

Simple steps to add a click event listener to every element within a div

I need to assign a click handler to multiple elements and perform different actions based on which one is clicked. To illustrate, I can create an alert displaying the class of the button that was clicked. The elements I am working with have a similar str ...

How can I adjust the number of columns displayed per page on a Bootstrap Studio website?

Currently, I am utilizing Bootstrap studio to design a website featuring multiple cards on each page. Initially, I incorporated cards from the sb-admin-2 template and everything was proceeding smoothly. In my bootstrap studio interface, the three-column ca ...

Ways to display a collection of random images with a click of a button?

I've created a simple php webpage that is supposed to display random images from my images folder when a button is clicked. However, I'm facing an issue where no images are showing up and I can't seem to pinpoint the problem in my code. ...

Connections transition among associated HTML pages

I am working on my very first website using HTML and I'm encountering some challenges with maintaining consistency across pages. On the top of my page, I have a div containing some links. While they function correctly, I noticed that the spacing betw ...

Stable height with Internet Explorer 6

According to information found on davidwalsh, it is mentioned that in IE6, the container will continue to expand vertically even when a specific height is set. How can I establish a max-height in IE6 so that the container expands with its content until r ...

Utilizing event delegation for JavaScript addEventListener across multiple elements

How can I use event delegation with addEventListener on multiple elements? I want to trigger a click event on .node, including dynamically added elements. The code I have tried so far gives different results when clicking on .title, .image, or .subtitle. ...

What could be causing the issue of nth-child blocking the functionality of a:hover styles?

I have a unique collection of images that are styled to resemble polaroid pictures. Each image is given a slight rotation. a.polaroid { transform: rotate(-2deg); } On hover, a scale transformation is applied. a.polaroid:hover { transform: scale(1 ...

Ensure that the HTML link is valid and authenticated using SESSIONS

When creating a website, one of the initial tasks I like to tackle is adding links at the bottom of the page for checking valid HTML and CSS: HTML5  •   CSS <div> <a href="http://validator.w3.org/check?uri=referer" ...

Vue JS nested component does not appear in the document object model

I developed two separate VueJS components - one displaying a modal and the other featuring HTML input fields. When I attempt to nest these two components, the inner component fails to appear in the DOM. What could be causing this issue? Here's a snip ...

Having trouble implementing responsive image with fixed aspect ratio code

I've tried several tutorials online to make this image responsive with a fixed aspect ratio, but nothing seems to work. The image is set at 900x400px and I want it to remain fully visible on smaller screens as well. Here's the codepen link < ...

What is the best way to fill out border boxes in Bootstrap 4 for horizontal text alignment?

I'm struggling with this code snippet: <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/> <div class="row border border-success"> <div class="cols-12 col-sm-6 col-lg-4" class="b ...

What is the process of using an if statement in jQuery to verify the existence of a property in a JSON file?

I am working on a task to incorporate an if statement that checks for the existence of a specific property in a JSON file. If the property exists, I need to display its value within HTML tags <div class='titleHolder'> and "<div class=&ap ...

Leveraging this jQuery code across multiple div elements

As a newcomer to jQuery, I am currently experimenting with a test script. My goal is to create an effect where when an image is clicked, a div slides down displaying more information similar to the new google images effect. The issue with the current scri ...