Hiding scrollbars in a component: The ultimate guide

I am seeking a way to completely hide scrollbars from an HTML component using CSS styles within a VueJS component. I have tried the solution of using overflow-y: hidden; within the component as well as within a specific subclass in the CSS, but neither completely removes the scrollbars while still allowing for scrolling functionality. I require a functional scroll panel without the visible scrollbars in various browsers. I have come across a code snippet like the following:

-ms-overflow-style: none;
scrollbar-width: none;

:-webkit-scrollbar {
    display: none;
    -webkit-appearance: none;
}

Implementing this code within the CSS class of a custom list worked in Firefox, but the scrollbars are still visible in Chrome and Safari when they shouldn't be. Sources for this code include this and similar discussions, but they have not provided a solution that works consistently across browsers. Below is an example of the widget component code:

.v-root {
    .v-component-widget {
        .v-component-widget-header{
            .v-component-widget-header-list{
                position: absolute;
                overflow: scroll;

                //Disable scrollbars
                -ms-overflow-style: none;
                scrollbar-width: none;

                :-webkit-scrollbar {
                    display: none;
                    -webkit-appearance: none;
                }
            }
        }
    }
}

These classes are applied to specific div blocks with a hierarchy matching the nesting classes shown here.

Answer №1

The website you mentioned provides a detailed solution and explanation.

selector {
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none;  /* IE 10+ */
}

selector::-webkit-scrollbar {  /* WebKit & Blink */
  width: 0px;
  height: 0px;
}

::-webkit-scrollbar is specifically for Blink and WebKit-based browsers like Chrome, Edge, Opera, Safari, and iOS browsers. Reference - https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-scrollbar

scrollbar-width is for Firefox on the web and Android. Reference - https://developer.mozilla.org/en-US/docs/Web/CSS/scrollbar-width

-ms-overflow-style was previously used for IE but has been deprecated and removed from MDN documentation.

You might have made a typo in your code, consider using :: instead of : for -webkit-scrollbar.

Demo:

.div {
  max-width: 400px;
  max-height: 200px;
  border: 1px solid gray;
  overflow-y: scroll;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE 10+ */
}

.div::-webkit-scrollbar { /* WebKit & blink */
  width: 0px;
  height: 0px;
}
<div class="div">
  Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam ... (content continues)
</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

I'm looking for assistance in setting up a static sidebar within a two column layout. Any takers

Seeking assistance to fix the issue of making the right sidebar static when user begins scrolling. I am relatively new to responsive web design. I have attempted using the "position:fixed" property, but uncertain about its compatibility with responsive d ...

What is the best way to customize the woocommerce.css file in the parent theme?

Currently, I have incorporated an ecommerce-friendly wordpress theme for my website in conjunction with woocommerce. To customize the design, I created a child theme and transferred the woocommerce.css file from the plugin into the css of the child theme, ...

The video continues playing even after closing the modal box

I am facing an issue with my code where a video continues to play in the background even after I close the modal. Here is the code snippet: <div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria- ...

Utilize a Material UI GridList to transform images into a captivating background display

Incorporating a GridList displaying a variety of images fetched from an external source, I have successfully created an ever-changing image gallery. Now, my goal is to convert this dynamic image gallery into grayscale or transparency and utilize it as a ba ...

Is there a way to protect my Nuxt.js client-side code from being accessed by unauthorized users, akin to the way .htaccess

I am in the process of launching a Nuxt.js app with a domain, but it is still in development and I do not want anyone to access the client-side source code without a specific password. While using a `.htaccess` file can restrict access on Apache servers, ...

The submission of the form is not functioning properly after loading the page using AJAX

Having trouble submitting my form after loading the page with ajax. Here is the code I am using to load the page: The problem occurs after loading the ajax form as a modalbox. function account_list(url) { $.ajax({ type: 'get', url: url, befor ...

Creating a scrolling sidebar in Bootstrap 4

Today I learned about CSS Bootstrap 4 and created my template with a sidebar. However, when there are many menus, I want the sidebar to show a scrollbar. I am looking for help on how to make a scrollbar appear on my sidebar template. Below are my HTML and ...

Determine the active state of the router link to correspond with the prop

I am currently tackling a Vue project that involves vue-router with deeply nested routes, such as 2/company/staff/1/timeline. However, I have encountered an issue at the (...) /staff/:id section where all route links are appearing as active regardless of ...

Toggle visibility of div content when hovering over a link by leveraging the data attribute, with the div initially visible

I have a collection of links: <p><a href="#" class="floorplan initial" data-id="king"><strong>King</strong></a><br> 4 Bedrooms x 2.5 Bathrooms</p> <p><a href="#" class="floorplan" data-id="wood">< ...

Creating artwork using a "graphite drawing tool" on a blank canvas

I created a script that draws a series of lines on a canvas, giving it a sketch-like appearance. However, I have encountered two issues with the script. Firstly, why is the y value appearing to be twice as much as it should be? Secondly, why is the line w ...

Looking to simultaneously interact with two objects using VUEJS

I am looking to display POSTS and USERINFO simultaneously, ensuring that the correct user avatar is shown for each post. Objects posts : {!! $posts !!}, userinfo : {!! $userinfo !!}, Template < v-cloak v-for="post in posts"> <div v-b ...

php - assign image to picture through file location

My webpage features an img element with the following code: <img id=".."class=".." src="setPhoto/second_photo.php"> In the source attribute, I have linked to a .php file: <?php $id = $_SESSION['u_id']; $sql = "SELECT * FROM users WHER ...

What steps can I take to correct this CSS code? I am looking to update the content using CSS

Here is the code I have for the specific page shown in the screenshot: https://i.sstatic.net/57o2Z.jpg I want to change 'Replay course' to 'Access course'. Can anyone help me figure out what I'm missing? a.course-card__resume { d ...

Adjusting Image Size According to Window Resize?

My current issue involves having four images displayed side by side. When the window size is adjusted or viewed on a smaller device, the layout shifts to a line jump (with three images in a row and the fourth one below). What I actually want is for all fou ...

Is the trigger feature malfunctioning in Chrome?

Recently, I implemented a trigger function in order to enable another function by triggering the text box. Unfortunately, I am experiencing difficulties as it does not seem to be working properly on Google Chrome. Any assistance you can provide would be ...

Creating a toggler in Bootstrap version 5.1: A comprehensive guide

I am currently trying to set up a Navbar toggler using the guidance provided in the Bootstrap v5.1 documentation. My intention is to have the brand name displayed on the left and the toggler on the right. However, even though the code appears to be set up ...

Ways to verify if a web URL is contained within an HTML textbox

In the process of developing a frontend form for WordPress, I have incorporated a basic HTML textbox for users to input a web URL. My goal now is to ensure that the entered value is indeed a valid URL and not just arbitrary text. Is there a way to perfor ...

Tips for utilizing the Ace editor validator without the need to create a new Ace editor instance

In my React application, I utilize react-ace to build a CSS text editor. The implementation looks something like this... import Ace from 'react-ace' ... <Ace mode="css" value={value} onChange={onValueChange} onValidate ...

Deconstructing JavaScript scripts to incorporate HTML5/CSS3 functionality for outdated browsers such as Internet Explorer

I have been researching various resources and guides related to different scripting libraries, but none of them seem to address all the inquiries I have regarding performance and functionality. With so many scripts available, it can be overwhelming to dete ...

The XmlUtil.serialize(root) function is converting empty tags into self-closing tags

Check out this cool code snippet featuring an empty div tag (<div></div>): import groovy.xml.DOMBuilder import groovy.xml.XmlUtil def HTML_STRING = ''' <html> <div></div> <div>Some text</d ...