How can I eliminate the tiny white square located beneath the scrollbar track?

`::-webkit-scrollbar{
    width: 12px;
}

body::-webkit-scrollbar-track{
    background: #f1e9e9;
    border-radius: 10px;
    margin-block: 0.1875rem;
}

::-webkit-scrollbar-thumb{
    background-color: #582965;
    border-radius: 10px;
    border: 3px solid #ffffff;
}

::-webkit-scrollbar-thumb:hover{
    background-color: #40144d;
}

::-webkit-scrollbar-track:horizontal{
    display: none;
}`

This snippet of code was created to style a scrollbar in CSS and despite its functionality, an inexplicable white square appears below the scrollbar. Any insights or suggestions on how to troubleshoot this issue would be greatly appreciated. For those interested in delving deeper into the project's codebase, feel free to visit this link.

Here is an image depicting the issue:

I have exhausted all possible solutions that come to mind, but the problem persists.

Answer №1

Due to the presence of "overflow:scroll" for both horizontal and vertical axes, a small white square appears where they intersect.

Instead, use

overflow-y:scroll

and eliminate the need for

::-webkit-scrollbar-track:horizontal{
   display: none;
}

Answer №2

The intersection of both scrollbars creates the corner on a webpage. If you have enabled scrolling in both directions, this corner will be visible. In browsers that support WebKit, you can customize the appearance of this corner using CSS.

::-webkit-scrollbar-corner {
    background-color: transparent ; 
}

::-webkit-scrollbar-corner {
    /* Set the background color to yellow for visibility */
    background-color: yellow ;
}
<div style="width:200px; height:200px; overflow:auto;background-color:red">
    <div style="height:500px; width:200px; background-color:blue"></div>
</div>

Answer №3

When it comes to creating a vertically scrollable div, the W3 doc suggests:

To achieve a scrollable bar, utilize the x and y-axis. Set overflow-x: hidden; and overflow-y: auto; to hide the horizontal scrollbar while showing the vertical one automatically.

The information provided by the MDN web docs on overflow-y is as follows:

The overflow-y CSS property determines how content appears when it overflows a block-level element's top and bottom edges. It can be nothing, a scroll bar, or the overflowing content itself. This property can also be specified using the overflow shorthand property.

Looking at The Overflow Property (which showcases a similar issue you might be facing) versus The overflow-y Property. To address your specific case, simply add a line like this:

main .description {
max-height: 5rem;
font-size: 14px;
padding-right: 0.625rem;
overflow-y: scroll; /****----- allow vertical scroll only -----****/
}

The code snippet below demonstrates how this property works in practice:

const toggleThemeButton = document.getElementById("theme-toggle-button");
const body = document.querySelector("body");
const themeToggleButtonImage = document.querySelector(".toggle-button-image");

toggleThemeButton.addEventListener("click", () => {
  const darkModeActive = body.classList.contains("dark-mode");

  body.classList.toggle("dark-mode");

  if (darkModeActive) {
    themeToggleButtonImage.setAttribute("src", "./src/images/sun.png");
  } else {
    themeToggleButtonImage.setAttribute("src", "./src/images/moon.png");
  }
});
/****----- RESET -----****/
*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

ul{
    list-style: none;
}

/****----- MAIN -----****/

body{
    font-family: 'Poppins', sans-serif;
    max-width: 80rem;
    margin: 0 auto 0 auto;
    background-color: #5e5b5bad;
    color: #333333;
}
body.dark-mode{
    background-color: #212121;
    color: #f5f5f5;
}

header{
    display: flex;
    justify-content: space-between;
    padding: 1.5625rem;
}

header .logo,
header .toggle-button-image{
    width: 1.875rem;
    transition: 0.2s ease-in-out;
}

header #theme-toggle-button{
    background: none;
    border: none;
}

header .logo:hover,
header .toggle-button-image:hover,
main .pokemon-card:hover{
    transform: scale(1.05);
    cursor: pointer;
}

main{
    padding: 1.5625rem;
}

main .pokemon-list {
    display: flex;
    flex-wrap: wrap;
    gap: 1.875rem;
    justify-content: center;
}

main .pokemon-card{
    background-color: #d8e3ec;
    width: 12.5rem;
    padding: 0.9375rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.9375rem;
    border-radius: 15px;
    transition: 0.2s ease-in-out;
}

main .pokemon-card:hover{
    background-color: #96d9d6;
}

.dark-mode .pokemon-card {
    background-color: #a8a8a8;
}

main .pokemon-card .information{
    display: flex;
    justify-content: space-between;
    border: 0.0625rem solid #333333;
    border-radius: 10px;
}

main .pokemon-card .gif{
    width: 60px;
    height: 60px;
}

main .pokemon-card .information span{
    padding: 0.3125rem;
    text-transform: uppercase;
    font-size: 1.0625rem;
}

main .pokemon-card .types {
    display: flex;
    gap: 0.9375rem;
}
  
main .pokemon-card .type{
    padding: 0.5rem;
    border-radius: 10px;
}

.grass{
    background-color: #9bcc50;
}

.poison{
    background-color: #b97fc9;
}

.fire{
    background-color: #fd7d24;
}

.water{
    background-color: #4592c4;
}

.flying{
    background-color: #3dc7ef;
}

.bug{
    background-color: #729f3f;
}

.normal{
    background-color: #83898b;
}

.electric{
    background-color: #eed535;
}

.ground{
    background-color: #ab9842;
}

.fairy{
    background-color: #fdb9e9;
}

main .description {
    max-height: 5rem;
    font-size: 14px;
    padding-right: 0.625rem;
    overflow-y: scroll; /****----- authorize vertical scroll only -----****/
}

/****----- SCROLLBAR -----****/

::-webkit-scrollbar{
    width: 12px;
}

body::-webkit-scrollbar-track {
    background: #d8e3ec;
    border-radius: 10px;
    margin-block: 0.1875rem;
}

::-webkit-scrollbar-thumb{
    background-color: #582965;
    border-radius: 10px;
    border: 3px solid #ffffff;
}

::-webkit-scrollbar-thumb:hover{
    background-color: #40144d;
}

::-webkit-scrollbar-track:horizontal{
    display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<header>
    <a href="https://www.pokemon.com/br/pokedex/" target="_blank">
        <img src="./src/images/pokeball.png" 
        alt="pokeball" 
        class="logo">
    </a>
    <button id="theme-toggle-button">
        <img src="./src/images/sun.png" 
        alt="sun image" 
        class="toggle-button-image">
    </button>
</header>
<main>
    <ul class="pokemon-list">
        <li class="pokemon-card">
            <div class="information">
                <span>Bulbasaur</span>
                <span>#0001</span>
            </div>

            <img src="./src/images/bulbasaur.gif" alt="Bulbasaur" class="gif">

            <ul class="types">
                <li class="type grass">Grass</li>
                <li class="type poison">Poison</li>
            </ul>

            <p class="description">There is a plant seed on its back since the day this Pokémon was born. The seed grows slowly.</p>
        </li>
       <!-- More Pokemon cards go here -->
    </ul>
</main>

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 causes offsetHeight to be less than clientHeight?

INFORMATION: clientHeight: Retrieves the height of an element, taking into account padding offsetHeight: Obtains the height of an element, considering padding, border, and scrollbar Analyzing the Data: The value returned by offsetHeight is expected to ...

Struggling with dynamically updating fields based on user input in real time

I have a goal to update a field based on the inputs of two other fields. Currently, all the fields are manual input. Below is the code I'm using to try and make the "passThru" field update in real-time as data is entered into the other fields. The ma ...

CSS - fixed table headers

Check out my CodePen example here - Code In this demo, I have a table inside a container where the table is larger than the container. As you scroll horizontally, both the table and headers move accordingly. However, when scrolling vertically, I want th ...

What is causing my JS/JQuery code to only function in the console of a web browser?

I am having trouble with the $(element).scroll(function(){}); function. When I put it into a js file, it does not work properly, but when I enter it directly into the console (just the scroll func), it works fine. My goal is to implement scrolling paginat ...

"Troubleshooting: Click counter in HTML/Javascript unable to function

My latest HTML project is inspired by the "cookie clicker" game, and I'm working on it for a friend. So far, I've managed to get the click counter to function to some extent. Essentially, when you click on the image, the number at the bottom sho ...

When a table cell is hovered over, a left border will be added

I've been working on adding a left border to the text in a way that highlights the first cell's border when hovering over a row, providing a clear indication of the current row for users. Feel free to check out my progress so far on this fiddle: ...

Running a Node.js child process upon clicking an HTML button

I need to create a basic webpage where clicking a button will open the command prompt. This is my goal. Below are the HTML and Node.js code snippets. test.html <html> <head> </head> <body> <p>guru</p> <form a ...

How to implement jquery select functionality on clickable table rows?

I've come across a challenge while trying to implement clickable table rows with the jquery selectable function. Everything works perfectly fine with li elements, but I seem to hit a roadblock when using tables - the click event just stops working. Wh ...

How can I add content using HTML or JavaScript?

How can I append a .txt file using HTML or Java without ActiveX prompts getting in the way? It's becoming quite annoying! Is there a simple way to script this task without having to deal with ActiveX? The current script snippet looks something like ...

Utilize JSON data fetched from a URL to dynamically populate an HTML content

There is a JSON file located at a URL that looks like this: [{"tier":"SILVER","leagueName":"Tryndamere's Wizards","queueType":"RANKED_SOLO_5x5","playerOrTeamId":"91248124", "playerOrTeamName":"NunoC99","leaguePoints":18,"wins":411,"losses":430,"rank" ...

Is it possible to redirect my PDF File to my PHP homepage?

Hi there, I've been looking for a solution to my issue. I have been using TCPDF-master to create a PDF report. However, after generating the PDF file and printing it out, I am unsure of how to redirect back to my transaction page. My current setup inv ...

After clicking the submit button, how can I eliminate the following: "config.php?username=++psw&Text=psw&submit=send?" and remain on the same page?

Whenever I hit the submit button on my form, PHP completes its task but instead of staying on the page (or simply reloading it), I am redirected to the same URL with '/config.php?username=technologies.%0D%0A++&submit = Send ". Is there a way ...

The Jquery function .load() doesn't load HTML comment tags as expected

Utilizing the .load() Jquery function enables me to insert html tags from one file into another. Here is an example of the code: <html> <head> <script src="jquery.js"></script> <script> function loadConte ...

"Engaging with the touchscreen inhibits the triggering of click

Within this div, I have implemented touch-action:pan-y;. Surrounding this div is an anchor tag. If you click on the div, the link will successfully redirect. However, if you swipe on the div and then click, the link won't work on the first attempt bu ...

Tips for incorporating a visible HTML comment in JSX code?

Currently implementing ReactJS and facing a requirement to insert visible HTML comments (visible in the html source) within JSX. Unsure of the correct approach to achieve this. A third party vendor necessitates this comment for processing purposes on the ...

Creating an HTML Canvas using an AngularJS template

I am facing an issue with rendering html elements on a canvas using html2canvas JS. I am utilizing AngularJS for data binding on the html page, but unfortunately, the dynamic data is not showing up on the canvas generated from these html elements. For inst ...

Is there a method in PHP to conceal HTML code?

Although I understand that obfuscated html/js code may seem unnecessary to some (I've read similar questions on SO), I still want to add an extra layer of protection against potential copycats of my site... My website is php-based and generates html ...

Embedding a YouTube video in a view player using HTML5

So I've got a question: can you actually open a youtube video using an HTML5 video player? I'm looking for a more mobile-friendly way to watch youtube videos, and my idea was to upload a thumbnail image and then set up an onclick function to disp ...

Should pages be indexed to index.php or should the top and bottom parts of the page be created and included in all content pages?

I've been out of the webpage creation game for a while, but I've recently decided to get back into it. Like everyone else, I want to learn the best way to do this. However, I find myself facing a dilemma on how to structure my pages. My initial i ...

FlexNav excluding

I have implemented FlexNav for my website navigation. The demo I used sets the width of top-level menu items to 20%, which works well with five menu items. .flexnav li { . . . width: 20%; } However, in my menu, the text lengths of the top ...