Mysterious extra space appearing on the right side of the left scroll div in Chrome

I am currently working with a table that dynamically increases in content when a button is clicked. I have successfully implemented a scroll on the right side to handle overflow. However, I encountered an issue when trying to change the scroll to the left side - there seems to be a mysterious padding on the right side of the outer-wrapper div element. This problem only manifests when inspecting and hovering over the DOM element, and strangely, it only occurs in Chrome. I have tested it in Mozilla and everything works perfectly.

<div class="test-container">
  <div class="outer-wrapper">
    <div class="inner-wrapper">
      <table class="table">
        <tr>
          <td class="content-box">
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
          </td>
        </tr>
      </table>
    </div>
  </div>
  <button type="button" id="click-me">
  Click Me to Fill
  </button>
</div>

The issue specifically lies within the outer-wrapper, which exhibits an unexplained extension to the right during inspection.

For reference, you can view the code on this fiddle

Additionally, here is a screenshot showcasing the problem: https://i.stack.imgur.com/kSDcy.jpg

Answer №1

If you want to prevent horizontal scrolling on WebKit browsers, you can use overflow-y: overlay;. This setting ensures that the viewport remains the same width without any unwanted scrollbars.

$('#click-me').click(function(){
$('.table .content-box').append('<p>test</p>');
});
.test-container{
  width:100%;
  border:1px solid lightgray;
  height:530px;
  overflow:hidden;
}
.outer-wrapper{
  border:1px solid lightgray;
  height:530px;
  width:320px;
  overflow-y:auto;
  overflow-y:overlay;
  box-sizing:border-box;
  display:inline-block;
  direction:rtl;
}
.inner-wrapper{
  width:290px;
  direction:ltr;
  /* border:1px solid yellow; */
}
button{
  display:inline-block;
  width:30%;
  margin-left:50px;
  margin-top:10px;
  /* text-align:right; */
  vertical-align:top;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<div class="test-container">
  <div class="outer-wrapper">
    <div class="inner-wrapper">
      <table class="table">
        <tr>
          <td class="content-box">
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
            <p>Test</p>
          </td>
        </tr>
      </table>
    </div>
  </div>
  <button type="button" id="click-me">
  Click Me to Fill
  </button>
</div>

Answer №2

Switching outer-wrapper from rtl to ltr appears to resolve the problem.

Could the inconsistency in rtl/ltr be responsible for the issue?

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

iPhone height is not correct

One issue I faced was when trying to view a webpage in landscape mode on iPhones (specifically testing on model SE, but it appears that many people are experiencing the same problem with other iPhone models). I have created a simple example below, consist ...

Tips for positioning an image in the TOP Right corner below the navbar using CSS

I am currently in the process of learning HTML and CSS, and I would like to practice and conduct research whenever I encounter difficulties. Recently, I have been attempting to style my landing page based on a screenshot that I took. However, I have been u ...

Ways to adjust the div height to match the span height

.headerDesc { width: 100% + 1px; height: 70px; background-color: #4d2765; margin: 0 -8px; } .headerDesc span { padding: 5px; position: absolute; color: white; font-family: 'Arial', sans-serif; text-al ...

Why is it that the default theme of Material UI lacks any stylization at all?

After experimenting with both Carbon Design for React (@carbon/react) and Material UI (@mui/material) in conjunction with Next.js, I encountered styling issues with the components. While they functioned correctly to some extent, there were noticeable discr ...

CSS - Implementing responsive design to ensure optimal viewing experience on all devices

Card Matching Game Project Codepen Check out my CSS here, and find the rest of the code on Codepen since it's quite lengthy. const cards = document.querySelectorAll('.memory-card'); let hasFlippedCard = false; let lockBoard = false; let ...

Angular application experiencing issues with fixed headers not scrolling correctly

I've been working on implementing a fixed header for one of my pages in an Angular application, but I'm having some trouble getting it to work as expected. Currently, when the user expands the accordions on the page and scrolls down, the headers ...

Is there a way to use jQuery to focus the cursor on a specific field in a form?

In my form, the first field is a dropdown with options such as "student" and "employee". Below that, there are two text fields for "college name" and "company name". If a person selects "student", then the "college name" text box should be enabled and t ...

Elevate a div over another div

I have a situation where I need to nest two divs inside another div with the ID "video-wrapper". Here is the HTML code: <div class="row"> <div class="video-wrapper col-lg-2"> <div class="video-thumbnail"> <img ...

I'm having trouble locating the HTML link in my text

I've recently started coding and I'm facing an issue. I can't seem to figure out why a link named "Food Taxi" isn't showing up. I added an href tag, but it's still not linking properly. I've tried moving some code around witho ...

Guide on showcasing all entries in the database within the body section of an HTML table

Looking to showcase data from a table inside the body section of an html page This is the code I've been working on: <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="vi ...

Drop the prohibited cursor before dragging

Is there a way to change the cursor behavior during element drag using HTML5 default drag and drop with TypeScript? I have tried various methods like changing from ev.target.style.cursor to "grab" cursor, adjusting dropEffect, etc., but none of them give m ...

Using line breaks in JSX

In my application, I save all the text in a settings.ts file. However, I am facing an issue where \n does not seem to add line breaks as expected. Are there any alternative methods to include breaklines in my text? My tech stack includes Next.js, Reac ...

Display issue on Safari when using flexbox?

I'm currently experiencing an issue with uploading a webpage to my domain, specifically on Safari. I have applied all the necessary prefixes, but it seems that the error lies with the display: flex property. When viewed on Chrome, the page looks like ...

The CSS does not get applied to the returned element in Next JS

When I create a function to return a DOM element with an associated className, the local style doesn't seem to be applied. For example: export default function thing(){ const elem = function(){ return (<div className="myCss">Hello< ...

Tips for updating the current user's username value in local storage in Angular

https://i.stack.imgur.com/ZA32X.png https://i.stack.imgur.com/iDHZW.png I am facing an issue with updating the local storage of a current User for only username. When I update the username, it's not reflecting in local storage. Even though I can s ...

Toggling Bootstrap Tooltip divs within a nested structure triggers the Tooltip of the parent div

I have a setup with 2 nested <div> elements, both utilizing the tooltip() function. When I hover over the inner <div>, the tooltip of the outer <div> also displays. To resolve this issue, I attempted to clear the title of the inner <di ...

Load an external script once the page has finished loading by leveraging the power of $(document).ready() in conjunction with $.getScript()

Is it possible to load a script in the header of a website instead of at the bottom? I've been trying but it's not working as expected. Here is an example of what I'm attempting: HTML file: <!DOCTYPE html> <html lang="en"> < ...

Using a class variable to access canvas methods in Javascript

As someone new to Javascript, I am facing a bit of confusion when it comes to classes and objects. Recently, I refactored some code into a working class but the process did not go as smoothly as I had hoped. Despite searching through Stackoverflow, Google ...

Verifying the number of div elements within an if condition

I've been attempting to determine the number of div elements in my DOM. However, when I try to assign this count to a variable, it displays as undefined in the console. Strangely, when I utilize an alert, it correctly shows the value as "8". My goal ...

Clicking on a Vuetify v-btn with the :href attribute set to download will open the XML file

I'm having trouble getting the v-btn to download an XML file instead of opening it in the browser. <v-btn :disabled="!exportUrl" block x-large height="100" color="primary" :href="exportUrl" download> ...