Is it feasible to adjust the Scrollbar's position?

Is there a way to change the position of a scrollbar on a webpage?

Are there any alternative solutions for this issue?

<div style="overflow: scroll; overflow-y: hidden">

 </div>

I am looking to relocate the scrollbar to a different component instead of having it inside this specific div.

Currently, my setup looks like this:

<div id="table_container" style="width: 100%; margin: 0 auto;">
<table style="width:200px;border: 1px solid black;float: left;">
  This is data that I don't want to scroll so it remains stable even when the other table is scrolled horizontally.
 </table>

<div class="results" id="contractList" style="overflow: scroll; overflow-y: hidden">
<table style="border: 1px solid black;float: left;">
 This table is meant to be scrollable horizontally while the first one stays fixed.
 </table>
 </div>
 </div>

My goal is to enable vertical scrolling for all content in the first div by adding overflow: scroll; overflow-x: hidden, while still allowing horizontal scrolling for the second table without being restricted to the bottom of the first div.

Answer №1

Achieving this is totally doable through the combination of JavaScript and CSS within an HTML environment;-)

I have prepared a code snippet for you on the W3Schools TryIt Editor. Simply copy and paste the code to see it in action. I believe no further explanation is necessary.

<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
#content
{
  width: 200px;
  overflow-x: hidden;
  overflow-y: auto;
  white-space: pre;
  background-color: red;
}
#scrollbar
{
  width: 200px;
  overflow-x: scroll;
  overflow-y: hidden;
  /*setting background color to transparent eliminates the blue line above the scrollbar*/
  background-color: blue;
}
#innerScrollbar
{
  height: 1px;
  line-height: 1px;
  font-size: 1px;
  visibility: hidden;
  background-color: yellow;
}
</style>
<script type="text/javascript">

//snippet to calculate browser's scrollbar width, taken from http://www.alexandre-gomes.com/?p=115
function getScrollBarWidth()
{
  var inner = document.createElement('p');
  inner.style.width = "100%";
  inner.style.height = "200px";

  var outer = document.createElement('div');
  outer.style.position = "absolute";
  outer.style.top = "0px";
  outer.style.left = "0px";
  outer.style.visibility = "hidden";
  outer.style.width = "200px";
  outer.style.height = "150px";
  outer.style.overflow = "hidden";
  outer.appendChild (inner);

  document.body.appendChild (outer);

  var w1 = inner.offsetWidth;
  outer.style.overflow = 'scroll';
  var w2 = inner.offsetWidth;
  if (w1 == w2) w2 = outer.clientWidth;

  document.body.removeChild (outer);

  return (w1 - w2);
};

//function to update scrollbar on page load and while scrolling content
function updateScrollbar(content, scrollbar)
{
  scrollbar.getElementsByTagName('*')[0].style.width = content.scrollWidth + "px";
  content.scrollLeft = scrollbar.scrollLeft;
}

</script>
</head>
<body onload="updateScrollbar(document.getElementById('content'), document.getElementById('scrollbar'))">

  <div id="content">Insert your content here. You can reposition the scrollbar div as needed. Note that the scrollbar itself will still be dictated by the browser or OS.</div>

  ...other website elements...

  <div id="scrollbar" onscroll="updateScrollbar(document.getElementById('content'), this)"><div id="innerScrollbar"><!--dummy text--></div></div>
  <script type="text/javascript">
    //adjusting scrollbar-container height to scrollbar height + 1,
    //ensures proper display of the scrollbar!
    document.getElementById('scrollbar').style.height  =(getScrollBarWidth() + 1) + "px";
  </script>

</body>
</html>

Oh wait, upon reviewing your question once more, your requirement is now crystal clear. You just need to generate X number of tables with vertical scrolling enabled. Position the scrollbar div at the bottom after the tables and make some javascript adjustments looping through the tables:

innerscrollbar.style.width = maxWidthFromTables + "px";
tables[i].scrollLeft = scrollbar.scrollLeft;

To calculate maxWidthFromTables, fetch the maximum width using: tables[i].scrollWidth;

Answer №2

A workaround to achieve this is by adjusting the width of the page to 100% and adding a div element with scrolling capability. This will prevent the scroll bar from appearing on the main page.

Here's an example of the CSS code:

body,html{ margin: 0; padding:0; height: 100%; overflow: hidden}
.mydiv { width: 200px; height: 200px; position: absolute; top: 200px; left: 200px; overflow-y: scroll}

And here's how you would implement it in HTML:

<body><div class="mydiv">Put a very large content here</div></body>

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

Passing props down in Next.js when working with children components

Within my Next js page, I have a component structured as follows: ... <Chart isShoppingChartOpen={isShoppingChartOpen} toggleShoppingChart={toggleChartVisibility} lineItems={lineItems} /> <main className= ...

Tips for asynchronously updating a model in TypeScript

I have been working on a function to hide the element for connecting to Facebook upon successful connection. I have implemented two functions, success and error, which trigger after Firebase successfully logs in the user. While I can confirm that these fun ...

Is there a way for me to include a transition in the text of the picture's caption?

I've been attempting to incorporate a transition:1s; and transition the text to color:#0000. The specific text I'm working with is 'Joe Doe' in the image caption below my image. I've experimented with various placements in my CSS, ...

How can I determine the specific font used in an image through Google Fonts?

I remember seeing how to do this once on a website, possibly html5rocks, but now I can't seem to figure it out. Maybe there is someone out there who can help me with this. I want to know what font was used in this picture and if it is hosted on Googl ...

What is the best way to send a confirmation to a customer, complete tasks in the background, and then deliver the final results to the customer?

I am currently working on developing a REST API that can process Excel data efficiently. My goal is to inform the client once their files have been successfully received. app.post('/upload', upload.fields([{name: 'raw'},{name: 'rep ...

Learn the steps to emphasize the first row of a material table using React

Within my react application, there is a material table that I have styled using the following code snippet: <MaterialTable options={{ exportButton: true, exportAllData: true, pageSize: 5, pageSizeOptions: [5, 10, 15 ...

Expand a list item to full width based on the number of items present

Is there a way to make dynamically added list items in a footer stretch across the width of their container? The footer is created in WordPress and the list items are actually widgets. Here is an example: Fiddle I can't manually set the width for e ...

Displaying file when JQuery dialog is opened

I am utilizing a JQuery dialog to load a partial view within it. $("#WOdialog").dialog({ width: 765, resizable: false, closeOnEscape: true, modal: true, clos ...

Can you use logical AND in Selenium XPath to combine multiple contains() filters?

My objective is to identify a specific element using Selenium: <a class="ABC" href="#" data-test-id="XXX|YYY|ZZZ"> There are various elements on the page with attributes matching "ABC", "XXX", " ...

Having difficulty executing a function inside a JavaScript file

Within my index.php file, the following lines of code are present: <!doctype html><html class=""><head><title>a title</title> <link href="_css/boilerplate.css" rel="stylesheet" type="text/css"> <script type="text/jav ...

Implementing authentication fallback during re-login when a session expires in a web application built with React, Node.js, and Mariadb database

Greetings everyone, this is my debut post here so kindly bear with me :D. Currently, I am in the process of developing a social app where I am incorporating a fallback mechanism for situations when my database goes offline. Within my Login.jsx component, I ...

The Boostrap Datepicker fails to display

I'm having trouble integrating a Bootstrap Datepicker into my form. I got it working outside of the form, but when I try to include the code in my form, it doesn't seem to work. All necessary files are present and the code is identical. <!D ...

Ensuring the Selection with jQuery

I've successfully implemented jQuery validation on a text field, but when I try to apply it to a radio button, it doesn't seem to work. I'm not sure what I'm doing wrong. Here is my HTML and jQuery code: <input type="text" placehol ...

Is it possible to assign a Bootstrap class as a variable in a custom CSS declaration?

While trying to make my website responsive, I planned on using media queries to adjust text size and other elements. The issue arises because I rely on bootstrap for setting text sizes. Is there a way to apply bootstrap classes in my CSS file? For instanc ...

What is the best way to detect input events from the Stripe cardElement to determine if a card is invalid and then proceed to disable the button?

While my user fills out the form with order information and customer details, I ensure that the submit button remains disabled until all validations are met. The library being used for this purpose is express-validate. In addition to the current setup, I ...

Limit the radius to only apply on big screens using tailwind css

Is there a way to apply border radius to an image only on larger screens and maintain straight edges on smaller screens? I'm working with Nextjs and Tailwind CSS. ...

Text input field for username not visible on screen

https://i.stack.imgur.com/2UUQl.png After designing the login page for my current project, I seem to have accidentally hidden the username text input. Can anyone explain why this is happening and provide guidance on how to make it visible again? ...

JavaScript - Identifying Repetitive Items in an Array

My goal is difficult to explain in words, but I can show you with code. Here is the array I am working with: var array = [{name:"John",lastname:"Doe"},{name:"Alex",lastname:"Bill"},{name:"John",lastname:"Doe"}] This array has duplicate elements, and I n ...

Encountering a 404 error indicating that the file cannot be found while attempting to log into an authentication system developed using express and node

Currently, I am in the process of developing a demonstration banking application that facilitates user sign up and sign in functionality using express.js and node.js. The API created accepts POST requests to /signup and /authenticate routes successfully wh ...

How can I effectively handle extensive data parsing from a file using JavaScript?

Looking to optimize data parsing in JavaScript for a large file? I'm currently using JSON parse for a 250MB file, but it's too slow. Is there a faster method to extract a high volume of data without iterating through every character? The file con ...