How do I implement a scroll bar for a specific section on a webpage?

After finding the solution to this particular question, I encountered a similar issue on a different page.

 <div style="white-space: nowrap;">
    <span style="display: inline-block; width: 280px">...</span>
    <span style="display: inline-block; width: 280px">...</span>
    <span style="display: inline-block; width: 280px">...</span>
    <span style="display: inline-block; width: 280px">...</span>
 </div>

In this case, if there are numerous spans, they will continue horizontally on the page without wrapping, causing a horizontal scroll bar to appear. Each span contains an html table which may or may not be relevant to the problem at hand.

While this setup functions effectively, an issue arises when one of the spans is significantly longer vertically than the others. In such cases, users must scroll down vertically to access the horizontal scroll bar. I am seeking a way to ensure that the horizontal scroll bar remains visible regardless of the vertical length of any specific span.

One good example of this behavior can be seen in applications like Trello (refer to the screenshot below). When a section is exceptionally long vertically, it adds a vertical scroll bar exclusively for that segment, avoiding the need to scroll the entire page.

In my scenario, each span contains an html table. How should I proceed to implement a vertical scroll bar solely for these tables, without affecting the rest of the page?

Answer №1

To ensure proper display, apply a max-height and overflow-y to the inner elements, as well as set sizes for the outer elements:

HTML

<div class="outer">
    <div class="inner">apple</div>
    <div class="inner">banana</div>
    <div class="inner">cherry</div>
</div>

CSS

.outer {
    border: 2px solid green;
    float:right;
    top:10px;
    bottom:20px;
    position:relative;
}
.inner {
    max-height:80%;
    overflow-y:auto;
    border: 1px dashed orange;
    width:50%;
    margin-right:5%;
    float:left;
}

View the working example here

Answer №2

div, section {height: 100%}

.what_encloses_your_span {overflow-y: scroll; max-height: 100%;}

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

Use PHP to post videos or images online

I'm having trouble uploading videos or pictures to my server using PHP. Every time I try, I receive an error stating that the file name is empty. I don't understand why this is happening, as the code continues to run the script, displaying an err ...

What is the best way to locate the offspring of a parent div using its data attribute?

If I have a container div called dvMainDiv with multiple child divs inside it, all added programmatically, how can I retrieve a specific child div based on its data-id attribute? <div id="dvMainDiv" class="dvMainDiv"> <div id="dvChildDiv" cla ...

When you add the measurements of two images to the top bar, you get the viewport size

Requirement 1: A top bar measuring 46px in height Reqirement 2: One photo positioned at the top and another at the bottom I have attempted the techniques mentioned on How to resize an image to fit in the browser window?. However, the images still appear ...

Set iframe or form to be in a fixed position

Having issues with my site where an iframe is contained within a div. When only one character is entered in the telephone box, validation fails and red warning text is displayed. Furthermore, after clicking in the email box and pressing tab twice, the fo ...

What is the best way to position an image on top of a circular object?

I have a circle variable that I'm using in a canvas game. How can I add an image on top of it while still allowing the circle to move around the canvas? var img = new Image(); img.src = "img.png"; var ball = { radius: 0 ,position: { x: 0, ...

Issue: The value of an object is not defined (evaluating '$scope.inputcode.password')

HTML Form: <form ng-submit="mylogin()"> <div class="list"> <label class="item item-input"> <span class="input-label">Username</span> <input type="text" ng-model="inputcode.username"> ...

Achieving the perfect background image size using Tailwindcss

Looking for a way to use an image with a height of 300px and a width of 1600px as a background in a div element? Although the div element's height can be extended beyond 300px, it results in an empty space at the top while covering the width. The de ...

Unveiled absolute positioned element disrupts page layout when revealed

I'm facing an issue where an absolutely positioned element is causing content to move when it's displayed. You can see the problem in action by clicking on Profile in this fiddle. Can anyone help me understand what is causing this behavior and h ...

Tips for resolving a post 405 error on a Windows 2012 R2 server

My test application is designed to record camera footage and send the file to a directory on my server. The main code for this application is shown below: <!DOCTYPE html> <html> <head> <script src="https://cdn.WebRTC-E ...

Creating a horizontal scrollbar for multiple rows and columns in Bootstrap: A step-by-step guide

I need a solution where multiple rows and columns can be scrolled horizontally using just one scroll bar. I have already tried implementing the scrollbar for only one row with multiple columns, but it didn't work as expected. Here is the code that I a ...

Tips for positioning a div between two vertically aligned input elements

I'm trying to figure out how to place a div between two inputs with the same height and vertically aligned. It seems like a simple task, but for some reason, the code below isn't working: input{ width: 35%; border: 1px solid #A7A7A7; ...

image in the background following the header

Live Example: http://jsbin.com/opokev/54 I am currently trying to set this image as the background image while also including a header, but as you can see in the demo, the header is overlapping the image. Is there a way I can rearrange this so that the h ...

Notify when the focus is solely on the text box

How can I display an alert only when the focus is on a text box? Currently, I am getting an alert whenever I skip the text box or click anywhere on the page. The alert even appears when I open a new tab. Is there a way to fix this issue? Thank you for your ...

Tips on avoiding a page reload following a form submission using JQuery

Currently developing a website for my app development project, I've encountered an unusual issue. Utilizing some JQuery to transfer form data to a php page called 'process.php' and then add it to my database. The strange part is that the pa ...

Use jQuery to change the background color when clicked

Below is the HTML code with UL and LI elements: <UL> <LI><span id='select1'>Text</span></LI> <LI><span id='select2'>Text</span></LI> <LI><span id='select3'>Tex ...

Completely triggering a forced refresh on a single page application, disregarding cache, service workers, and all other

After experimenting with service workers on my Vue-built website, I made a critical error that has left Safari on my iPhone displaying only a blank page. To troubleshoot the issue, I connected my phone to my Mac and utilized Safari's inspector tool t ...

How can I implement user-specific changes using Flask?

I am a beginner with Flask and I am working on a project where users can sign up, and if the admin clicks a button next to their name, the user's homepage will change. Below is the Flask code snippet: from flask import Flask, redirect, url_for, render ...

Creating a Django URL path using an HTML search form

Within my template, I have implemented an input field with the type "search". Upon triggering an action, the page redirects to "/search_results.html". The current dilemma I am facing is that it is adding /?search=yoursearch to the end of the URL. This is ...

Press the div, excluding the button - Vue

I have a basic div that spans 100% of the width, containing a button inside. The issue I'm facing is that when I add a click event to the div, the entire div becomes clickable (including the button within it). What I want is for the whole div to be ...

Personalizing the presentation of asp.net webforms code

Having recently entered the asp.net realm, I've been intrigued by the talk surrounding asp.net mvc and its superior ability to customize markup and css compared to webforms. Despite hearing that asp.net is easier to learn than asp.net mvc, I've o ...